Simplify JagexGzipOutputStream

Deflater already tracks the size of the input.

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 3 years ago
parent 0d097f7d2c
commit 799277b386
  1. 5
      compress/src/main/kotlin/org/openrs2/compress/gzip/JagexGzipOutputStream.kt

@ -12,7 +12,6 @@ public class JagexGzipOutputStream(
private val deflater = Deflater(Deflater.DEFAULT_COMPRESSION, true) private val deflater = Deflater(Deflater.DEFAULT_COMPRESSION, true)
private val buffer = ByteArray(4096) private val buffer = ByteArray(4096)
private val checksum = CRC32() private val checksum = CRC32()
private var size = 0
private var closed = false private var closed = false
init { init {
@ -32,8 +31,6 @@ public class JagexGzipOutputStream(
override fun write(b: ByteArray, off: Int, len: Int) { override fun write(b: ByteArray, off: Int, len: Int) {
checksum.update(b, off, len) checksum.update(b, off, len)
size += len
deflater.setInput(b, off, len) deflater.setInput(b, off, len)
while (!deflater.needsInput()) { while (!deflater.needsInput()) {
@ -58,7 +55,7 @@ public class JagexGzipOutputStream(
val dataOutput = LittleEndianDataOutputStream(output) val dataOutput = LittleEndianDataOutputStream(output)
dataOutput.writeInt(checksum.value.toInt()) dataOutput.writeInt(checksum.value.toInt())
dataOutput.writeInt(size) dataOutput.writeInt(deflater.totalIn)
deflater.end() deflater.end()
output.close() output.close()

Loading…
Cancel
Save