From 47f4cc060a82e8e1133c828f026f4e94d4581b2c Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 14 Jan 2020 21:16:22 +0000 Subject: [PATCH] Add compress{Jar,Pack,Js5} to Resource --- .../main/java/dev/openrs2/bundler/Resource.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bundler/src/main/java/dev/openrs2/bundler/Resource.kt b/bundler/src/main/java/dev/openrs2/bundler/Resource.kt index 3a8bde6c..7336e66e 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Resource.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Resource.kt @@ -1,5 +1,7 @@ package dev.openrs2.bundler +import dev.openrs2.asm.classpath.Library +import java.io.ByteArrayOutputStream import java.security.MessageDigest import java.util.zip.CRC32 import java.util.zip.Deflater @@ -49,6 +51,27 @@ class Resource( return Resource(sourceWithCrc, destination, digest.digest(), uncompressed.size, content) } + fun compressJar(source: String, destination: String, library: Library): Resource { + ByteArrayOutputStream().use { out -> + library.writeJar(out) + return compress(source, destination, out.toByteArray()) + } + } + + fun compressPack(source: String, destination: String, library: Library): Resource { + ByteArrayOutputStream().use { out -> + library.writePack(out) + return compress(source, destination, out.toByteArray()) + } + } + + fun compressJs5(source: String, destination: String, library: Library): Resource { + ByteArrayOutputStream().use { out -> + library.writeJs5(out) + return compress(source, destination, out.toByteArray()) + } + } + private fun compress(source: String, destination: String, resource: String): Resource { val path = "/dev/openrs2/natives/$resource" val uncompressed = Resource::class.java.getResourceAsStream(path).use { it.readBytes() }