How to replace ZLibDeflater with ZLibEncoder

141 views Asked by At

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?

2

There are 2 answers

1
Alexandre Ardhuin On BEST ANSWER

You can also use ZLIB :

new File(filePath)
  .openRead()
  .transform(ZLIB.decoder)
  .pipe(new File(zlibPath).openWrite())
  .then(...);
0
Fox32 On

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(...)