@digitaldefiance/bzip2-wasm

中文文档
1.1.1发布于 2026/02/26bzip2-1.0.6TypeScriptES Module零依赖近 30 天下载 3192

compress and decompress bzip2 buffers in node and browser

原始使用文档
文档目录8 节
  1. install
  2. example
  3. api
  4. bzip2 = new BZip2()
  5. async bzip2.init()
  6. bzip2.compress(decompressed, blockSize = 5, compressedSize …
  7. bzip2.decompress(compressed = [], decompressedLength = 0)
  8. license

bzip2-wasm

(de)compress buffers in node and browser using wasm-compiled bzip2.

re-published identically from source, with the addition of typescript definitions added by Digital Defiance.

install

$ npm install bzip2-wasm

example

import BZip2 from "wasm-bzip2";
import fs from 'fs';

const bzip2 = new BZip2();

await bzip2.init();

const licenseText = fs.readFileSync('./LICENSE');
console.log('original length:', licenseText.length);

const compressed = bzip2.compress(licenseText);
console.log('compressed length:', compressed.length);

const decompressed = bzip2.decompress(compressed, licenseText.length);
console.log('decompressed length:', decompressed.length);

api

bzip2 = new BZip2()

async bzip2.init()

fetch and load the wasm. required for following methods.

bzip2.compress(decompressed, blockSize = 5, compressedSize = decompressed.length)

compress an array of bytes.

decompressed should be array-like (TypedArray or regular) of bytes.

blockSize should be a Number between 1-9 to determine block size (multiplied by 100k). default is 5 (500k).

compressedLength should be a Number that is at least large or larger than the resulting compressed data. default is decompressed.length.

returns a Uint8Array of compressed data.

bzip2.decompress(compressed = [], decompressedLength = 0)

decompress a compressed array of bytes.

compressed should be array-like (TypedArray or regular) of bytes.

decompressedLength should be a Number that is at least large or larger than the resulting decompressed data.

returns a Uint8Array of decompressed data.

license

This program, "bzip2", the associated library "libbzip2", and all documentation, are copyright (C) 1996-2019 Julian R Seward. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

  3. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

  4. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Julian Seward, [email protected] bzip2/libbzip2 version 1.0.8 of 13 July 2019

版本与发布记录

@digitaldefiance/bzip2-wasm 共发布 2 个版本,首次发布于 2026/02/26;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.1.1latest2026/02/268 个月前
1.1.02026/02/268 个月前

关于 @digitaldefiance/bzip2-wasm 的常见问题

@digitaldefiance/bzip2-wasm 是什么?

compress and decompress bzip2 buffers in node and browser

如何安装 @digitaldefiance/bzip2-wasm?

在项目目录运行 npm install @digitaldefiance/bzip2-wasm,或使用 pnpm add / yarn add / bun add。

@digitaldefiance/bzip2-wasm 支持 TypeScript 吗?

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

@digitaldefiance/bzip2-wasm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@digitaldefiance/bzip2-wasm 可以商用吗?

@digitaldefiance/bzip2-wasm 使用 bzip2-1.0.6 许可。声明的许可为 bzip2-1.0.6,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@digitaldefiance/bzip2-wasm 的下载量有多少?

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

@digitaldefiance/bzip2-wasm 还在维护吗?

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