Add compress{Jar,Pack,Js5} to Resource

master
Graham 5 years ago
parent 3ae85d50ef
commit 47f4cc060a
  1. 23
      bundler/src/main/java/dev/openrs2/bundler/Resource.kt

@ -1,5 +1,7 @@
package dev.openrs2.bundler package dev.openrs2.bundler
import dev.openrs2.asm.classpath.Library
import java.io.ByteArrayOutputStream
import java.security.MessageDigest import java.security.MessageDigest
import java.util.zip.CRC32 import java.util.zip.CRC32
import java.util.zip.Deflater import java.util.zip.Deflater
@ -49,6 +51,27 @@ class Resource(
return Resource(sourceWithCrc, destination, digest.digest(), uncompressed.size, content) 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 { private fun compress(source: String, destination: String, resource: String): Resource {
val path = "/dev/openrs2/natives/$resource" val path = "/dev/openrs2/natives/$resource"
val uncompressed = Resource::class.java.getResourceAsStream(path).use { it.readBytes() } val uncompressed = Resource::class.java.getResourceAsStream(path).use { it.readBytes() }

Loading…
Cancel
Save