regular / unbzip2-stream

streaming unbzip2 implementatio in pure javascript for node and browsers
Other
29 stars 23 forks source link

Stream ends prematurely #19

Closed GerwinBosch closed 5 years ago

GerwinBosch commented 6 years ago

The parser stops without an error when it only parsed a chunk. Example file

Example code

const bz2 = require("unbzip2-stream");
import * as fs from "fs";

async function readBzip(inFile, outFile)
  const streamIn = fs.createReadStream(inFile);
  streamIn
    .on("error", (e: any) => console.error("input Error", e))
    // .on("data", (data: any) => console.log(data))
    .on("close", () => console.log("input CLOSE"))
    .on("end", () => console.log("input end"))
    .on((readable: any) => console.log(" input readable"));
  const streamOut = fs.createWriteStream(outFile);
  streamIn
    .pipe(bz2())
    .on("error", (e: any) => console.error("bzip Error", e))
    // .on("data", (data: any) => console.log(data))
    .on("close", () => console.log("bzip close"))
    .on("end", () => console.log("bzip end"))
    .on("readable", (readable: any) => console.log(" bzip readable",readable))
    .pipe(streamOut);
  return new Promise((resolve, reject) => strmOut.on("end", () => resolve()).on("error", () => reject()));
};

Notice that the end event of bzip is thrown almost immediately

regular commented 6 years ago

I tried your example file with the code from README, and indeed, it stops after outputting roughly 1 MB (1048576 bytes to be precise).

regular commented 6 years ago

Turns out your example file is the concatenation of multiple, independently compressed files. That's legal and the original bunzip2 (the cli binary) has no trouble decoding such files. It's simply a feature that is not implemented here. The good news: it is currently being implemented.

regular commented 5 years ago

Fixed in unbzip2-stream@1.3.0