# node-int64 中文文档

规范地址：https://npmcn.com/package/node-int64/

版本：0\.4\.0
npm 元数据更新时间：2023-05-26T16:12:34.200Z
中文译文更新时间：2026-11-05T16:15:18.401Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/node-int64
原文对照：https://npmcn.com/package/node-int64/?lang=original
项目主页：https://github.com/broofa/node-int64
源码仓库：https://github.com/broofa/node-int64

## 关键信息（来自 npm 元数据）

- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2010-12-30T15:27:28.086Z
- 最新版本发布：2015-04-04T02:52:16.354Z
- 近 30 天下载量：235139218（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

支持在 JavaScript 中表示64位整数

## 安装

```sh
npm install node-int64
```

也可以使用：`pnpm add node-int64`、`yarn add node-int64`、`bun add node-int64`

## README

JavaScript 数字以 [IEEE 754 双精度浮标](http://steve.hollasch.net/cgindex/coding/ieeefloat.html)。不幸的是,这意味着它们丧失了超过+/- 2.% 53. 的数值的整数精度。 对于需要准确处理64位英寸的项目,例如 [节点-旋动](https://github.com/wadey/node-thrift)需要表演者 类似数字的课 INT64是那个班级.

It64的例子看起来和感觉很像JS本土数字。 举个例子...

```js
// First, let's illustrate the problem ...
> (0x123456789).toString(16)
'123456789' // <- what we expect.
> (0x123456789abcdef0).toString(16)
'123456789abcdf00' // <- Ugh!  JS doesn't do big ints. :(

// So let's create a couple Int64s using the above values ...

// Require, of course
> Int64 = require('node-int64')

// x's value is what we expect (the decimal value of 0x123456789)
> x = new Int64(0x123456789)
[Int64 value:4886718345 octets:00 00 00 01 23 45 67 89]

// y's value is Infinity because it's outside the range of integer
// precision.  But that's okay - it's still useful because it's internal
// representation (octets) is what we passed in
> y = new Int64('123456789abcdef0')
[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]

// Let's do some math.  Int64's behave like Numbers.  (Sorry, Int64 isn't
// for doing 64-bit integer arithmetic (yet) - it's just for carrying
// around int64 values
> x + 1
4886718346
> y + 1
Infinity

// Int64 string operations ...
> 'value: ' + x
'value: 4886718345'
> 'value: ' + y
'value: Infinity'
> x.toString(2)
'100100011010001010110011110001001'
> y.toString(2)
'Infinity'

// Use JS's isFinite() method to see if the Int64 value is in the
// integer-precise range of JS values
> isFinite(x)
true
> isFinite(y)
false

// Get an octet string representation.  (Yay, y is what we put in!)
> x.toOctetString()
'0000000123456789'
> y.toOctetString()
'123456789abcdef0'

// Finally, some other ways to create Int64s ...

// Pass hi/lo words
> new Int64(0x12345678, 0x9abcdef0)
[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]

// Pass a Buffer
> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]))
[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]

// Pass a Buffer and offset
> new Int64(new Buffer([0,0,0,0,0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4)
[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]

// Pull out into a buffer
> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).toBuffer()
<Buffer 12 34 56 78 9a bc de f0>

// Or copy into an existing one (at an offset)
> var buf = new Buffer(1024);
> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).copy(buf, 512);
```

## 常见问题

### node-int64 是什么？

支持在 JavaScript 中表示64位整数

### 如何安装 node-int64？

在项目目录运行 npm install node-int64，或使用 pnpm add / yarn add / bun add。

### node-int64 支持 TypeScript 吗？

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

### node-int64 支持 ESM 还是 CommonJS？

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

### node-int64 可以商用吗？

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

### node-int64 的下载量有多少？

根据 npm 官方下载统计，node-int64 在 2026/10/05 – 2026/11/03 这 30 天内被下载 235,139,218 次，日均约 7,837,974 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### node-int64 还在维护吗？

最新版本 0\.4\.0 发布于 2015/04/04（11 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2010/12/30。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

