Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def compress(input: Array[Byte]): Array[Byte] = {
  2. val bos = new ByteArrayOutputStream(input.length)
  3. val gzip = new GZIPOutputStream(bos)
  4. gzip.write(input)
  5. gzip.close()
  6. val compressed = bos.toByteArray
  7. bos.close()
  8. compressed
  9. }
  10.  
  11. def decompress(compressed: Array[Byte]): Option[String] =
  12. Try {
  13. val inputStream = new GZIPInputStream(new ByteArrayInputStream(compressed))
  14. scala.io.Source.fromInputStream(inputStream).mkString
  15. }.toOption
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement