Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The seek-bzip npm package is a pure-Javascript implementation of the BZIP2 decompression algorithm, which allows for random access seeking within bzip2 files. This package is particularly useful for applications that need to extract portions of large compressed files without having to decompress the entire file.
Random Access Decompression
This feature allows users to decompress a specific block of data from a bzip2 compressed file, starting at a specified byte. This is useful for extracting data from large files without the need to decompress the entire file.
const fs = require('fs');
const seekBzip = require('seek-bzip');
const compressedData = fs.readFileSync('path/to/compressed-file.bz2');
const start = 12345; // start byte for decompression
const decompressedData = seekBzip.decodeBlock(compressedData, start);
unbzip2-stream is a streaming bzip2 decompressor in pure JavaScript for Node.js. Unlike seek-bzip, it does not support random access seeking, but it is useful for streaming decompression of bzip2 files.
compressjs is a collection of pure JavaScript implementations of various data compression algorithms, including bzip2. It provides a broader range of compression algorithms compared to seek-bzip, but it may not support random access seeking within bzip2 files.
node-bzip is a bzip2 compression and decompression library for Node.js. It is a wrapper around the C++ libbz2 library, which means it is not pure JavaScript like seek-bzip. It offers fast performance but does not support random access seeking.
seek-bzip
is a pure-javascript Node.JS module adapted from 'node-bzip' and before that antimatter15's pure-javascript implementation for decoding bzip2 data. seek-bzip
currently only decodes buffers into other buffers, synchronously. Unlike node-bzip
, seek-bzip
can seek to and decode single blocks from the bzip2 file.
npm install seek-bzip
After compressing some example data into example.bz2
, the following with recreate that original data and save it to example
.
var Bunzip = require('seek-bzip');
var fs = require('fs');
var compressedData = fs.readFileSync('example.bz2');
var data = Bunzip.decode(compressedData);
fs.writeFileSync('example', data);
See the tests in the tests/
directory for further usage examples.
For uncompressing single blocks of bzip2-compressed data, you will need
an out-of-band index listing the start of each bzip2 block. (Presumably
you generate this at the same time as you index the start of the information
you wish to seek to inside the compressed file.) The seek-bzip
module
has been designed to be compatible with the C implementation seek-bzip2
available from https://bitbucket.org/james_taylor/seek-bzip2. That codebase
contains a bzip-table
tool which will generate bzip2 block start indices.
require('seek-bzip')
returns a Bunzip
object. It contains two static
methods. The first is a function accepting one or two parameters:
Bunzip.decode = function(Buffer inputBuffer, [Number expectedSize])
If expectedSize
is not present, decodeBzip
simply decodes inputBuffer
and returns the resulting Buffer
.
If expectedSize
is present, decodeBzip
will store the results in a Buffer
of length expectedSize
, and throw an error in the case that the size of the decoded data does not match expectedSize
.
The second is a function accepting two or three parameters:
Bunzip.decodeBlock = function(Buffer inputBuffer, Number blockStartBits, [Number expectedSize])
The inputBuffer
and expectedSize
parameters are as above.
The blockStartBits
parameter gives the start of the desired block, in bits.
The following improvements to this module would be generally useful. Feel free to fork on github and submit pull requests!
Streaming interface. The original micro-bunzip2
and seek-bzip2
codebases
contained a slightly more complicated input/output system which allowed
streaming chunks of input and output data. It wouldn't be hard to retrofit
that to this code base.
Port the bzip-table
tool from the seek-bzip2
codebase, so that index
generation is self-contained. Again, not very hard!
Add command-line binaries to the node module for bzip-table
and
seek-bunzip
.
Add compression along with decompression. See micro-bzip
at
http://www.landley.net/code/
Copyright © 2013 C. Scott Ananian
Copyright © 2012 Eli Skeggs
Copyright © 2011 Kevin Kwok
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/lgpl-2.1.html
FAQs
a pure-JavaScript Node.JS module for random-access decoding bzip2 data
The npm package seek-bzip receives a total of 3,011,897 weekly downloads. As such, seek-bzip popularity was classified as popular.
We found that seek-bzip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.