1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

Use *.jar.xz script bundle

This commit is contained in:
Reinhard Pointner 2016-10-28 04:03:42 +08:00
parent b43e74b11f
commit 23a4eba41a
4 changed files with 24 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import static java.util.stream.Collectors.*;
import static net.filebot.CachedResource.*;
import static net.filebot.Logging.*;
import java.io.InputStream;
import java.net.URL;
import java.time.Duration;
import java.util.List;
@ -32,6 +33,10 @@ public class Cache {
return new CachedResource<T, byte[]>(key, resource, fetchIfModified(), getBytes(), byte[].class::cast, ONE_DAY, this);
}
public <T> CachedResource<T, byte[]> bytes(T key, Transform<T, URL> resource, Transform<InputStream, InputStream> decompressor) {
return new CachedResource<T, byte[]>(key, resource, fetchIfModified(), getBytes(decompressor), byte[].class::cast, ONE_DAY, this);
}
public <T> CachedResource<T, String> text(T key, Transform<T, URL> resource) {
return new CachedResource<T, String>(key, resource, fetchIfModified(), getText(UTF_8), String.class::cast, ONE_DAY, this);
}

View File

@ -4,6 +4,7 @@ import static net.filebot.Logging.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@ -20,6 +21,8 @@ import java.util.function.Supplier;
import org.w3c.dom.Document;
import net.filebot.util.ByteBufferInputStream;
import net.filebot.util.ByteBufferOutputStream;
import net.filebot.util.JsonUtilities;
import net.filebot.web.WebRequest;
@ -138,6 +141,18 @@ public class CachedResource<K, R> implements Resource<R> {
};
}
public static Transform<ByteBuffer, byte[]> getBytes(Transform<InputStream, InputStream> decompressor) {
return (data) -> {
ByteBufferOutputStream buffer = new ByteBufferOutputStream(data.remaining());
try (InputStream in = decompressor.transform(new ByteBufferInputStream(data))) {
buffer.transferFully(in);
} catch (Exception e) {
throw new RuntimeException(e);
}
return buffer.getByteArray();
};
}
public static Transform<ByteBuffer, String> getText(Charset charset) {
return (data) -> charset.decode(data).toString();
}

View File

@ -8,7 +8,7 @@ update.url: https://app.filebot.net/update.xml
donate.url: https://app.filebot.net/donate.php
# base URL for resolving script resources
github.stable: https://app.filebot.net/scripts/m1.jar
github.stable: https://app.filebot.net/scripts/m1.jar.xz
github.master: https://raw.githubusercontent.com/filebot/scripts/master/
# native links

View File

@ -10,6 +10,8 @@ import java.io.File;
import java.net.URI;
import java.time.Duration;
import org.tukaani.xz.XZInputStream;
import net.filebot.Cache;
import net.filebot.CacheType;
import net.filebot.Resource;
@ -26,7 +28,7 @@ public enum ScriptSource {
@Override
public ScriptProvider getScriptProvider(String input) throws Exception {
URI resource = new URI(getApplicationProperty("github.stable"));
Resource<byte[]> bundle = getCache().bytes(resource, URI::toURL).expire(Cache.ONE_WEEK);
Resource<byte[]> bundle = getCache().bytes(resource, URI::toURL, XZInputStream::new).expire(Cache.ONE_WEEK);
return new ScriptBundle(bundle, getClass().getResourceAsStream("repository.cer"));
}