Search code examples
dartdart-io

How to replace ZLibDeflater with ZLibEncoder


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?


Solution

  • You can also use ZLIB :

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