2

I'm using the ZLibDeflater to compress a file, by reading it as a stream and transforming it:

new File(filePath)
   .openRead()
   .transform(new ZLibDeflater())
   .pipe(new File(gzipPath).openWrite())
   .then(...);

As the ZLibDeflater is now deprecated, how can I convert the code to use the new GZipCodec class?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Fox32
  • 13,126
  • 9
  • 50
  • 71

2 Answers2

5

You can also use ZLIB :

new File(filePath)
  .openRead()
  .transform(ZLIB.decoder)
  .pipe(new File(zlibPath).openWrite())
  .then(...);
Sungguk Lim
  • 6,109
  • 7
  • 43
  • 63
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
0

Gave up to early, you can simply do it using the Converter.bind() method to transform a stream:

const GZipCodec()
    .encoder.bind(new File(filePath).openRead())
    .pipe(new File(gzipPath).openWrite())
    .then(...)
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Fox32
  • 13,126
  • 9
  • 50
  • 71