Rename NONE to UNCOMPRESSED

This is the name used by Jagex.

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 8d35b5010a
commit 107c432e65
  1. 10
      cache/src/main/java/dev/openrs2/cache/Js5Compression.kt
  2. 6
      cache/src/main/java/dev/openrs2/cache/Js5CompressionType.kt
  3. 20
      cache/src/test/java/dev/openrs2/cache/Js5CompressionTest.kt

@ -23,7 +23,7 @@ public object Js5Compression {
input.alloc().buffer().use { output ->
output.writeByte(type.ordinal)
if (type == Js5CompressionType.NONE) {
if (type == Js5CompressionType.UNCOMPRESSED) {
val len = input.readableBytes()
output.writeInt(len)
output.writeBytes(input)
@ -85,7 +85,7 @@ public object Js5Compression {
* enableNoneWithKey? Or should LZMA also be disabled in clients
* with the decryption bug?
*/
types += Js5CompressionType.NONE
types += Js5CompressionType.UNCOMPRESSED
}
var best = compress(input.slice(), types.first(), key)
@ -118,7 +118,7 @@ public object Js5Compression {
throw IOException("Length is negative: $len")
}
if (type == Js5CompressionType.NONE) {
if (type == Js5CompressionType.UNCOMPRESSED) {
if (input.readableBytes() < len) {
throw IOException("Data truncated")
}
@ -173,7 +173,7 @@ public object Js5Compression {
throw IOException("Length is negative: $len")
}
if (type == Js5CompressionType.NONE) {
if (type == Js5CompressionType.UNCOMPRESSED) {
/*
* There is no easy way for us to be sure whether an uncompressed
* group's key is valid or not, as we'd need specific validation
@ -223,7 +223,7 @@ public object Js5Compression {
}
when (type) {
Js5CompressionType.NONE -> throw AssertionError()
Js5CompressionType.UNCOMPRESSED -> throw AssertionError()
Js5CompressionType.BZIP2 -> {
val magic = ByteArray(BZIP2_MAGIC.size)
plaintext.readBytes(magic)

@ -9,14 +9,14 @@ import java.util.zip.Deflater
import java.util.zip.GZIPInputStream
public enum class Js5CompressionType {
NONE,
UNCOMPRESSED,
BZIP2,
GZIP,
LZMA;
public fun createInputStream(input: InputStream, length: Int): InputStream {
return when (this) {
NONE -> input
UNCOMPRESSED -> input
BZIP2 -> Bzip2.createHeaderlessInputStream(input)
GZIP -> GZIPInputStream(input)
LZMA -> Lzma.createHeaderlessInputStream(input, length.toLong())
@ -25,7 +25,7 @@ public enum class Js5CompressionType {
public fun createOutputStream(output: OutputStream): OutputStream {
return when (this) {
NONE -> output
UNCOMPRESSED -> output
BZIP2 -> Bzip2.createHeaderlessOutputStream(output)
GZIP -> GzipLevelOutputStream(output, Deflater.BEST_COMPRESSION)
/*

@ -20,7 +20,7 @@ object Js5CompressionTest {
fun testCompressNone() {
read("none.dat").use { expected ->
Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { input ->
Js5Compression.compress(input, Js5CompressionType.NONE).use { actual ->
Js5Compression.compress(input, Js5CompressionType.UNCOMPRESSED).use { actual ->
assertEquals(expected, actual)
}
}
@ -119,7 +119,7 @@ object Js5CompressionTest {
fun testCompressNoneEncrypted() {
read("none-encrypted.dat").use { expected ->
Unpooled.wrappedBuffer("OpenRS2".repeat(3).toByteArray()).use { input ->
Js5Compression.compress(input, Js5CompressionType.NONE, KEY).use { actual ->
Js5Compression.compress(input, Js5CompressionType.UNCOMPRESSED, KEY).use { actual ->
assertEquals(expected, actual)
}
}
@ -206,12 +206,12 @@ object Js5CompressionTest {
@Test
fun testCompressBest() {
Unpooled.wrappedBuffer("OpenRS2".repeat(100).toByteArray()).use { expected ->
val noneLen = Js5Compression.compress(expected.slice(), Js5CompressionType.NONE).use { compressed ->
val noneLen = Js5Compression.compress(expected.slice(), Js5CompressionType.UNCOMPRESSED).use { compressed ->
compressed.readableBytes()
}
Js5Compression.compressBest(expected.slice()).use { compressed ->
assertNotEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertNotEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
assert(compressed.readableBytes() < noneLen)
Js5Compression.uncompress(compressed).use { actual ->
@ -224,12 +224,12 @@ object Js5CompressionTest {
@Test
fun testCompressBestEncrypted() {
Unpooled.wrappedBuffer("OpenRS2".repeat(100).toByteArray()).use { expected ->
val noneLen = Js5Compression.compress(expected.slice(), Js5CompressionType.NONE).use { compressed ->
val noneLen = Js5Compression.compress(expected.slice(), Js5CompressionType.UNCOMPRESSED).use { compressed ->
compressed.readableBytes()
}
Js5Compression.compressBest(expected.slice(), key = KEY).use { compressed ->
assertNotEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertNotEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
assert(compressed.readableBytes() < noneLen)
Js5Compression.uncompress(compressed, KEY).use { actual ->
@ -243,19 +243,19 @@ object Js5CompressionTest {
fun testUncompressedEncryption() {
Unpooled.wrappedBuffer("OpenRS2".toByteArray()).use { buf ->
Js5Compression.compressBest(buf.slice()).use { compressed ->
assertEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
}
Js5Compression.compressBest(buf.slice(), enableUncompressedEncryption = true).use { compressed ->
assertEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
}
Js5Compression.compressBest(buf.slice(), key = KEY).use { compressed ->
assertNotEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertNotEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
}
Js5Compression.compressBest(buf.slice(), key = KEY, enableUncompressedEncryption = true).use { compressed ->
assertEquals(Js5CompressionType.NONE.ordinal, compressed.getUnsignedByte(0).toInt())
assertEquals(Js5CompressionType.UNCOMPRESSED.ordinal, compressed.getUnsignedByte(0).toInt())
}
}
}

Loading…
Cancel
Save