StreamDecompress

case class StreamDecompress(compressorName: StreamableCompressor, in: InputStream)

Decompressing stream example

Decompressing stream example

val zStream     = StreamDecompress(StreamableCompressor.GZ, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.DEFLATE, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.BZ2, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.PACK200, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.XZ, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.ZSTANDARD, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.LZMA, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.LZ4, new FileInputStream("/tmp/compressedFile"))
//  val zStream     = StreamDecompress(StreamableCompressor.Snappy1, new FileInputStream("/tmp/compressedFile"))
val buffer       = new Array[Byte](2)
val decompressed = new StringBuilder

@tailrec
def readBuffer(): Unit = {
 zStream.readInBuffer(buffer) match {
   case Failure(exception) => exception.printStackTrace
   case Success(bytesRead) =>
     if (bytesRead != -1) {
       decompressed.append(new String(buffer, StandardCharsets.UTF_8))
       readBuffer()
     } else {
       println
       zStream.close()
     }
 }
}
readBuffer()
val cl: Try[Unit] = zStream.close()
assert(decompressed.toString == "foobar")

trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Concrete methods

def close(): Try[Unit]
def readInBuffer(buffer: Array[Byte]): Try[Int]

Inherited methods

def productElementNames: Iterator[String]
Inherited from
Product
def productIterator: Iterator[Any]
Inherited from
Product