@gmod/binary-parser

中文文档
1.4.2发布于 2024/06/23MITCommonJS近 30 天下载 5172

Blazing-fast binary parser builder

原始使用文档
文档目录4 节
  1. Installation
  2. Special data types
  3. Differences with keichi/binary-parser
  4. Example usage

binary-parser

Greenkeeper badge Build Status codecov

@gmod/binary-parser is a fork of https://github.com/keichi/binary-parser that also handles 64-bit longs and itf8 and ltf8 types

Installation

Binary-parser can be installed with npm:

$ npm install @gmod/binary-parser

Special data types

The ITF-8 and LTF-8 types documented in https://samtools.github.io/hts-specs/CRAMv3.pdf

The 64-bit parsing in this library is done by https://www.npmjs.com/package/long and simply returns .toNumber() on the parsed 64 bit data.

You can also access Long inside formatter callbacks (this is not possible in keichi/binary-parser since these are eval'd and the Long library instance is not available to the eval'd code)

Differences with keichi/binary-parser

  • This library is default little endian instead instead of big endian while https://github.com/keichi/binary-parser is default big endian

  • The return value of the parse {result: {<parsed results>},offset: <number of bytes parsed>} instead of just {<parsed results>}

Example usage

Example of reading a 64-bit int

new Parser()
.uint64('mylong64bitint')
.int64('mylong64bitint')

64 bit infers from the endianess of the .endianess, doesn't use uint64le/be

Verification of whether the long is a valid 2^53 int is not done for 64 bit numbers. If you require this make a custom callback using Long in a formatter for buffer

版本与发布记录

@gmod/binary-parser 共发布 7 个版本,首次发布于 2018/09/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.2latest2024/06/232 年前
1.4.12021/09/255 年前
1.4.02021/09/245 年前
1.3.52019/04/127 年前
1.3.42019/04/087 年前
1.3.32019/01/127 年前

关于 @gmod/binary-parser 的常见问题

@gmod/binary-parser 是什么?

Blazing-fast binary parser builder

如何安装 @gmod/binary-parser?

在项目目录运行 npm install @gmod/binary-parser,或使用 pnpm add / yarn add / bun add。

@gmod/binary-parser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/gmod__binary-parser 是否存在。

@gmod/binary-parser 支持 ESM 还是 CommonJS?

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

@gmod/binary-parser 需要什么版本的 Node.js?

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

@gmod/binary-parser 可以商用吗?

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

@gmod/binary-parser 的下载量有多少?

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

@gmod/binary-parser 还在维护吗?

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