101arrowz / fflate

High performance (de)compression in an 8kB package

Home Page:https://101arrowz.github.io/fflate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect argument order in AsyncFlateStreamHandler

ethanshry opened this issue · comments

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.

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.

@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?

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

Fixed and will release in v0.8.1.

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