@nirs4all/formats-wasm

中文文档
0.2.14发布于 2026/11/02CECILL-2.1 OR AGPL-3.0-or-laterTypeScriptCommonJS零依赖构建来源已验证

WebAssembly bindings for nirs4all-formats.

原始使用文档
文档目录5 节
  1. Build
  2. Surface
  3. Sidecar formats
  4. Scope & feature flags
  5. Smoke test

nirs4all-formats (WebAssembly / JS)

Browser- and Node-friendly bridge to the nirs4all-formats Rust core. It runs the format sniffers and the decoders entirely in WebAssembly, from in-memory bytes — no filesystem required.

Build

# Browser (ES modules)
wasm-pack build bindings/wasm --target web --release
# Node.js / Bun
wasm-pack build bindings/wasm --target nodejs --release --out-dir pkg-node

This emits the JS glue, .wasm binary, and TypeScript typings under pkg/ (or pkg-node/). Tagged releases publish that surface as @nirs4all/formats-wasm on npm.

Surface

import init, {
  version, features, readerCatalog, probeBytes, openBytes, openWithSidecars,
} from "./pkg/nirs4all_formats_wasm.js";

await init();

version();   // "0.1.0-alpha.1"
features();  // { hdf5: true, matlab: true, parquet: true }
readerCatalog(); // [{ reader: "nirs4all_formats::readers::jcamp" }, ...]

const bytes = new Uint8Array(await file.arrayBuffer());

// Sniff: ordered candidate readers, best first
probeBytes(file.name, bytes);
// [{ format: "jcamp-dx", reader: "...", confidence: "definite", reason: "..." }]

// Decode: SpectralRecord[] (same JSON shape as `nirs4all-formats read-json`)
const records = openBytes(file.name, bytes);

openBytes / probeBytes take the file name (several sniffers disambiguate by extension) plus the bytes. The returned records match the data model: signals, signal_type, targets, metadata, provenance, quality_flags.

Sidecar formats

Multi-file formats (ENVI Standard .img+.hdr, ENVI SLI, AVIRIS/ERDAS LAN, FGI XML+HDF5, NetCDF MFRSR) return an UnsupportedSidecar error from openBytes. Supply the companions as a { name: Uint8Array } map instead:

const records = openWithSidecars("cube.img", imgBytes, { "cube.hdr": hdrBytes });

Scope & feature flags

The default WASM build compiles fmt-hdf5, fmt-matlab, and fmt-parquet on. HDF5/NetCDF-backed readers, MATLAB MAT/RData readers, and Parquet table readers are available in the browser, including snappy, uncompressed, and zstd-compressed Parquet pages. Call features() to check the active bundle at runtime.

Smoke test

node bindings/wasm/tests/smoke.js
node bindings/wasm/tests/sidecars.test.js
node bindings/wasm/tests/fixture_matrix.js

smoke.js loads committed fixtures (CSV, JCAMP-DX, ASD binary, a non-data PDF) and asserts the probe routes each to the expected reader; sidecars.test.js exercises openWithSidecars. fixture_matrix.js opens a wider set of committed single-file and sidecar fixtures through the WASM package, checks expected non-NIRS/refusal paths, and compares the exercised readers to readerCatalog(). The committed matrix covers every compiled reader except Allotrope ADF, whose sample is local-only/non-redistributable; see samples/allotrope_adf/README.md.

版本与发布记录

@nirs4all/formats-wasm 共发布 16 个版本,首次发布于 2026/06/12;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.14latest2026/11/021 天前
0.2.132026/10/294 天前
0.2.122026/10/285 天前
0.2.112026/10/0529 天前
0.2.102026/09/171 个月前
0.2.92026/09/032 个月前

关于 @nirs4all/formats-wasm 的常见问题

@nirs4all/formats-wasm 是什么?

用于nirs4all格式的WebAssembly绑定。

如何安装 @nirs4all/formats-wasm?

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

@nirs4all/formats-wasm 支持 TypeScript 吗?

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

@nirs4all/formats-wasm 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@nirs4all/formats-wasm 可以商用吗?

@nirs4all/formats-wasm 使用 CECILL-2.1 OR AGPL-3.0-or-later 许可。可在 CECILL-2.1、AGPL-3.0 中任选其一遵守。以上为概括,不构成法律意见,请以许可原文为准。

@nirs4all/formats-wasm 还在维护吗?

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