How to replace ZLibDeflater with ZLibEncoder

155 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 best solutions below

1
On BEST ANSWER

You can also use ZLIB :

new File(filePath)
  .openRead()
  .transform(ZLIB.decoder)
  .pipe(new File(zlibPath).openWrite())
  .then(...);
0
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(...)