You might try using scalax.io as an alternative to scala-arm to return a Traversable[Byte]
which will lazily read from the stream
def inflate(data: Array[Byte]): Traversable[Byte] = {
val inflater = new InflaterInputStream(new ByteArrayInputStream(data), new Inflater)
Resource.fromInputStream(inflater).bytes
}
or you can convert this Traversable[Byte]
into an Array[Byte]
which will read the entire InputStream
into memory:
def inflate(data: Array[Byte]): Array[Byte] = {
val inflater = new InflaterInputStream(new ByteArrayInputStream(data), new Inflater)
Resource.fromInputStream(inflater).bytes.toArray
}
Here's how you might use the Deflater
:
def deflate(data: Array[Byte]) = {
val outputStream = new ByteArrayOutputStream
Resource.fromOutputStream(new DeflaterOutputStream(outputStream, new Deflater)).write(data)
outputStream.toByteArray
}