src/Pure/General/bytes.scala
changeset 80376 201af0b45e57
parent 80375 c33d017fc1a6
child 80377 28dd9b91dfe5
equal deleted inserted replaced
80375:c33d017fc1a6 80376:201af0b45e57
   471   def uncompress_xz(cache: Compress.Cache = Compress.Cache.none): Bytes =
   471   def uncompress_xz(cache: Compress.Cache = Compress.Cache.none): Bytes =
   472     using(new xz.XZInputStream(stream(), cache.for_xz))(Bytes.read_stream(_, hint = size))
   472     using(new xz.XZInputStream(stream(), cache.for_xz))(Bytes.read_stream(_, hint = size))
   473 
   473 
   474   def uncompress_zstd(cache: Compress.Cache = Compress.Cache.none): Bytes = {
   474   def uncompress_zstd(cache: Compress.Cache = Compress.Cache.none): Bytes = {
   475     Zstd.init()
   475     Zstd.init()
   476 
   476     using(new zstd.ZstdInputStream(stream(), cache.for_zstd))(Bytes.read_stream(_, hint = size))
   477     def uncompress_stream(hint: Long): Bytes =
       
   478       using(new zstd.ZstdInputStream(stream(), cache.for_zstd)) { inp =>
       
   479         Bytes.read_stream(inp, hint = hint)
       
   480       }
       
   481 
       
   482     if (chunks.isEmpty) {
       
   483       zstd.Zstd.decompressedSize(chunk0, offset.toInt, size.toInt) match {
       
   484         case 0 => Bytes.empty
       
   485         case n if n <= Bytes.array_size && !is_sliced =>
       
   486           Bytes.reuse_array(zstd.Zstd.decompress(chunk0, n.toInt))
       
   487         case n => uncompress_stream(n)
       
   488       }
       
   489     }
       
   490     else uncompress_stream(size / 2)
       
   491   }
   477   }
   492 
   478 
   493   def uncompress(cache: Compress.Cache = Compress.Cache.none): Bytes =
   479   def uncompress(cache: Compress.Cache = Compress.Cache.none): Bytes =
   494     if (detect_xz) uncompress_xz(cache = cache)
   480     if (detect_xz) uncompress_xz(cache = cache)
   495     else if (detect_zstd) uncompress_zstd(cache = cache)
   481     else if (detect_zstd) uncompress_zstd(cache = cache)