seek-bzip is a pure-JavaScript Node.js module (version 2.0.0, last published over 6 years ago) designed for random-access decoding of bzip2 data. Its primary differentiator is the ability to seek to and decompress individual blocks within a bzip2 file, provided an external index. It mainly operates synchronously, decoding buffers into other buffers. While it offers experimental support for Node.js streams, this functionality relies on the `fibers` package, which is deprecated and largely incompatible with modern Node.js versions (v16+), severely limiting its utility in current environments. The package also includes a `seek-bzip-table` tool for generating the necessary block indices.
npm install seek-bzipVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic synchronous buffer-to-buffer decompression using `Bunzip.decode`. It includes a warning that a real bzip2 file (not the dummy one created in the example) is required for successful operation.
Avoid using stream input/output for `Bunzip.decode` or `Bunzip.decodeBlock` in modern Node.js environments. Restrict usage to Buffer-based operations, or consider alternative bzip2 libraries for stream support. If stream support is critical, you might need to use an older Node.js version (e.g., 14.x or earlier) with a compatible `fibers` version.
Use tools like `seek-bzip-table` (available in the package's `bin` directory) or the C implementation `seek-bzip2`'s `bzip-table` to generate these block indices beforehand.
When using stream-like input/output, ensure your custom stream object strictly adheres to the required `readByte`, `seek`, and `writeByte` interfaces as specified in the documentation. For simpler use cases, stick to `Buffer` inputs and let the method return a `Buffer`.
For large files, consider offloading `seek-bzip` operations to a worker thread (if using Node.js versions that support it) or exploring alternative bzip2 libraries that offer asynchronous processing. Use `seek-bzip` primarily for smaller datasets where synchronous blocking is acceptable.
Ensure you are using the CommonJS `require` syntax: `const Bunzip = require('seek-bzip');`. Verify that `Bunzip` is correctly assigned before calling its methods.Either remove the `expectedSize` parameter if the size is unknown or non-critical, or ensure the provided `expectedSize` accurately reflects the uncompressed data's byte length. Validate the integrity of your bzip2 source file.
Modify your custom input stream object to include a `seek(position)` method that sets the stream's read position, or provide a `Buffer` as input instead of a stream for `decodeBlock`.
Ensure the `input` argument is either a Node.js `Buffer` containing the compressed bzip2 data or a custom object that implements a `readByte()` method to sequentially fetch bytes from the source.