Buffer CRC32

1.0.0 · abandoned · verified Sun Apr 19

buffer-crc32 provides a pure JavaScript implementation of the CRC32 algorithm, designed to work seamlessly with binary data and various character encodings by internally casting strings to Buffers. It offers methods to compute the CRC32 checksum and retrieve results as raw Buffer objects, signed integers, or unsigned integers. The library also supports an "append mode," allowing for incremental CRC calculations across multiple data chunks. Currently at version 1.0.0, this package has not seen updates in approximately seven years, suggesting it is stable but effectively abandoned. It requires Node.js version 8.0.0 or higher, potentially posing compatibility challenges for very modern environments that are primarily ESM-based or require newer Node.js features. Its key differentiator is its self-contained, pure JavaScript nature, avoiding native module dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage with buffers and strings, showing signed/unsigned integer conversion and the append mode for incremental CRC calculations.

import crc32 from 'buffer-crc32';

// Works with Buffers
const buf = Buffer.from([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]);
console.log('Buffer CRC32:', crc32(buf).toString('hex'));

// Convenience methods for signed or unsigned ints
console.log('Signed CRC32:', crc32.signed(buf));
console.log('Unsigned CRC32:', crc32.unsigned(buf));

// Automatically casts strings to buffers, supporting foreign characters
console.log('String CRC32 (自動販売機):', crc32('自動販売機').toString('hex'));

// Append mode for incremental calculation
let partialCrc = crc32('hey');
partialCrc = crc32(' ', partialCrc);
partialCrc = crc32('sup', partialCrc);
partialCrc = crc32(' ', partialCrc);
const finalCrc = crc32('bros', partialCrc);
console.log('Appended CRC32:', finalCrc.toString('hex'));

view raw JSON →