buffer-crc32

中文文档
1.0.0发布于 2024/02/07MITTypeScriptESM + CJS零依赖近 30 天下载 3.6亿

A pure javascript CRC32 algorithm that plays nice with binary data

原始使用文档

buffer-crc32

NPM Version Build Status

crc32 that works with binary data and fancy character sets, outputs buffer, signed or unsigned data and has tests.

Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix

This package requires Node 8+ to work.

install

npm install buffer-crc32

example

const crc32 = require('buffer-crc32');
// works with buffers
const buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]);
crc32(buf); // -> <Buffer 94 5a ab 4a>

// has convenience methods for getting signed or unsigned ints
crc32.signed(buf); // -> -1805997238
crc32.unsigned(buf); // -> 2488970058

// will cast to buffer if given a string, so you can
// directly use foreign characters safely
crc32('自動販売機'); // -> <Buffer cb 03 1a c5>

// and works in append mode too
const partialCrc = crc32('hey');
const partialCrc = crc32(' ', partialCrc);
const partialCrc = crc32('sup', partialCrc);
const partialCrc = crc32(' ', partialCrc);
const finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>

tests

This was tested against the output of zlib's crc32 method. You can run the tests withnpm test (requires tap)

see also

https://github.com/alexgorbatchev/node-crc, crc.buffer.crc32 also supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).

license

MIT/X11

版本与发布记录

buffer-crc32 共发布 24 个版本,首次发布于 2012/07/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2024/02/072 年前
1.0.0-RC9next2024/02/032 年前
1.0.0-RC82024/02/032 年前
1.0.0-RC72024/02/032 年前
1.0.0-RC52024/02/032 年前
1.0.0-RC42024/02/032 年前

关于 buffer-crc32 的常见问题

buffer-crc32 是什么?

A pure javascript CRC32 algorithm that plays nice with binary data

如何安装 buffer-crc32?

在项目目录运行 npm install buffer-crc32,或使用 pnpm add / yarn add / bun add。

buffer-crc32 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

buffer-crc32 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

buffer-crc32 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

buffer-crc32 可以商用吗?

buffer-crc32 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

buffer-crc32 的下载量有多少?

根据 npm 官方下载统计,buffer-crc32 在 2026/10/07 – 2026/11/05 这 30 天内被下载 356,786,062 次,日均约 11,892,869 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

buffer-crc32 还在维护吗?

最新版本 1.0.0 发布于 2024/02/07(2 年前);至今共发布 24 个版本,其中过去 12 个月发布了 0 个;首次发布于 2012/07/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。