101arrowz / fflate

High performance (de)compression in an 8kB package
https://101arrowz.github.io/fflate
MIT License
2.21k stars 77 forks source link

Incorrect argument order in AsyncFlateStreamHandler #179

Closed ethanshry closed 12 months ago

ethanshry commented 1 year ago

How to reproduce Install the library:

npm i --save fflate@0.8.0

Run the following code:

import { Decompress, gzipSync } from "fflate";

const d = new Decompress((err, chunk, final) => {
  console.log(err, chunk, final);
});

d.push(gzipSync(Buffer.from("Hello, fflate!")));

Declared type for the AsyncDecompress handler is:

export declare type AsyncFlateStreamHandler = (err: FlateError | null, data: Uint8Array, final: boolean) => void;

Expected log output: null Uint8Array(14)... false Recieved log output: Uint8Array(14)... false undefined

The problem

As per the documentation, I would expect arguments to be in the order err, chunk, final, however it looks like arguments are instead chunk, final, err.

101arrowz commented 1 year ago

Decompress is synchronous and accepts a FlateStreamHandler, see these docs. Errors are thrown by push and not sent to the callback at all. AsyncDecompress is a different class entirely that does have the expected arguments.

ethanshry commented 1 year ago

@101arrowz It makes sense to me that Decompress should use FlateStreamHandler, while AsyncDecompress would use AsyncFlateStreamHandler, however I think those docs back up what I am seeing locally- the Decompress constructor accepts an AsyncFlateStreamHandler as the argument.

Maybe I am confused on the expected usage?

101arrowz commented 1 year ago

Ah I screwed up the types in the constructor. Will fix. Just use .ondata for now.

101arrowz commented 1 year ago

Fixed and will release in v0.8.1.

101arrowz commented 12 months ago

v0.8.1 should be out, let me know if there are any more issues!