diff --git a/source/net/filebot/Cache.java b/source/net/filebot/Cache.java index bb82bdeb..6c9dc2ff 100644 --- a/source/net/filebot/Cache.java +++ b/source/net/filebot/Cache.java @@ -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(key, resource, fetchIfModified(), getBytes(), byte[].class::cast, ONE_DAY, this); } + public CachedResource bytes(T key, Transform resource, Transform decompressor) { + return new CachedResource(key, resource, fetchIfModified(), getBytes(decompressor), byte[].class::cast, ONE_DAY, this); + } + public CachedResource text(T key, Transform resource) { return new CachedResource(key, resource, fetchIfModified(), getText(UTF_8), String.class::cast, ONE_DAY, this); } diff --git a/source/net/filebot/CachedResource.java b/source/net/filebot/CachedResource.java index 63a4c213..5f43762d 100644 --- a/source/net/filebot/CachedResource.java +++ b/source/net/filebot/CachedResource.java @@ -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 implements Resource { }; } + public static Transform getBytes(Transform 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 getText(Charset charset) { return (data) -> charset.decode(data).toString(); } diff --git a/source/net/filebot/Settings.properties b/source/net/filebot/Settings.properties index 5151ac44..9d7a757e 100644 --- a/source/net/filebot/Settings.properties +++ b/source/net/filebot/Settings.properties @@ -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 diff --git a/source/net/filebot/cli/ScriptSource.java b/source/net/filebot/cli/ScriptSource.java index 4f77a1a2..d48f0caf 100644 --- a/source/net/filebot/cli/ScriptSource.java +++ b/source/net/filebot/cli/ScriptSource.java @@ -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 bundle = getCache().bytes(resource, URI::toURL).expire(Cache.ONE_WEEK); + Resource bundle = getCache().bytes(resource, URI::toURL, XZInputStream::new).expire(Cache.ONE_WEEK); return new ScriptBundle(bundle, getClass().getResourceAsStream("repository.cer")); }