Add commands for packing and unpacking pack200/packclass files

Signed-off-by: Graham <gpe@openrs2.org>
Graham 3 years ago
parent cf6e7cf8e7
commit 2b3e9d318a
  1. 1
      asm/build.gradle.kts
  2. 4
      compress-cli/build.gradle.kts
  3. 10
      compress-cli/src/main/kotlin/org/openrs2/compress/cli/CompressCommand.kt
  4. 24
      compress-cli/src/main/kotlin/org/openrs2/compress/cli/pack200/Pack200Command.kt
  5. 24
      compress-cli/src/main/kotlin/org/openrs2/compress/cli/pack200/Unpack200Command.kt
  6. 23
      compress-cli/src/main/kotlin/org/openrs2/compress/cli/packclass/PackClassCommand.kt
  7. 23
      compress-cli/src/main/kotlin/org/openrs2/compress/cli/packclass/UnpackClassCommand.kt

@ -8,6 +8,7 @@ dependencies {
api(libs.bundles.asm)
api(libs.guice)
api(libs.jackson.databind)
api(libs.netty.buffer)
implementation(projects.buffer)
implementation(projects.cache)

@ -11,7 +11,9 @@ application {
dependencies {
api(libs.clikt)
implementation(projects.asm)
implementation(projects.compress)
implementation(projects.util)
}
publishing {
@ -24,7 +26,7 @@ publishing {
description.set(
"""
Tools for compressing and uncompressing headerless bzip2,
DEFLATE, gzip and LZMA files.
DEFLATE, gzip, LZMA, Pack200 and PackClass files.
""".trimIndent()
)
}

@ -11,6 +11,10 @@ import org.openrs2.compress.cli.gzip.GunzipLaxCommand
import org.openrs2.compress.cli.gzip.GzipCommand
import org.openrs2.compress.cli.lzma.LzmaCommand
import org.openrs2.compress.cli.lzma.UnlzmaCommand
import org.openrs2.compress.cli.pack200.Pack200Command
import org.openrs2.compress.cli.pack200.Unpack200Command
import org.openrs2.compress.cli.packclass.PackClassCommand
import org.openrs2.compress.cli.packclass.UnpackClassCommand
public fun main(args: Array<String>): Unit = CompressCommand().main(args)
@ -25,7 +29,11 @@ public class CompressCommand : NoOpCliktCommand(name = "compress") {
GunzipCommand(),
GunzipLaxCommand(),
LzmaCommand(),
UnlzmaCommand()
UnlzmaCommand(),
Pack200Command(),
Unpack200Command(),
PackClassCommand(),
UnpackClassCommand()
)
}
}

@ -0,0 +1,24 @@
package org.openrs2.compress.cli.pack200
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.defaultStdin
import com.github.ajalt.clikt.parameters.types.defaultStdout
import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import org.openrs2.compress.gzip.Gzip
import java.util.jar.JarInputStream
import java.util.jar.Pack200
public class Pack200Command : CliktCommand(name = "pack200") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
override fun run() {
JarInputStream(input).use { jarInput ->
Gzip.createHeaderlessOutputStream(output).use { gzipOutput ->
Pack200.newPacker().pack(jarInput, gzipOutput)
}
}
}
}

@ -0,0 +1,24 @@
package org.openrs2.compress.cli.pack200
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.defaultStdin
import com.github.ajalt.clikt.parameters.types.defaultStdout
import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import org.openrs2.compress.gzip.Gzip
import org.openrs2.util.io.DeterministicJarOutputStream
import java.util.jar.Pack200
public class Unpack200Command : CliktCommand(name = "unpack200") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
override fun run() {
Gzip.createHeaderlessInputStream(input).use { gzipInput ->
DeterministicJarOutputStream(output).use { jarOutput ->
Pack200.newUnpacker().unpack(gzipInput, jarOutput)
}
}
}
}

@ -0,0 +1,23 @@
package org.openrs2.compress.cli.packclass
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.defaultStdin
import com.github.ajalt.clikt.parameters.types.defaultStdout
import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import io.netty.buffer.ByteBufAllocator
import org.openrs2.asm.classpath.ClassPath
import org.openrs2.asm.io.JarLibraryReader
import org.openrs2.asm.io.PackClassLibraryWriter
public class PackClassCommand : CliktCommand(name = "packclass") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
override fun run() {
val classes = JarLibraryReader.read(input)
val classPath = ClassPath(ClassLoader.getPlatformClassLoader(), emptyList(), emptyList())
PackClassLibraryWriter(ByteBufAllocator.DEFAULT).write(output, classPath, classes)
}
}

@ -0,0 +1,23 @@
package org.openrs2.compress.cli.packclass
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.defaultStdin
import com.github.ajalt.clikt.parameters.types.defaultStdout
import com.github.ajalt.clikt.parameters.types.inputStream
import com.github.ajalt.clikt.parameters.types.outputStream
import io.netty.buffer.ByteBufAllocator
import org.openrs2.asm.classpath.ClassPath
import org.openrs2.asm.io.JarLibraryWriter
import org.openrs2.asm.io.PackClassLibraryReader
public class UnpackClassCommand : CliktCommand(name = "unpackclass") {
private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout()
override fun run() {
val classes = PackClassLibraryReader(ByteBufAllocator.DEFAULT).read(input)
val classPath = ClassPath(ClassLoader.getPlatformClassLoader(), emptyList(), emptyList())
JarLibraryWriter.write(output, classPath, classes)
}
}
Loading…
Cancel
Save