# smart-buffer 中文文档

规范地址：https://npmcn.com/package/smart-buffer/

版本：4\.2\.0
npm 元数据更新时间：2022-06-26T21:17:32.222Z
中文译文更新时间：2026-11-05T16:17:45.987Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：138 kB，14 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 6\.0\.0
- 运行依赖：0 个
- 首次发布：2013-11-03T08:38:38.969Z
- 最新版本发布：2021-08-07T06:18:54.397Z
- 近 30 天下载量：226118707（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：32（近 12 个月 0 个）

## 中文简介

智能缓冲器(Smart-buffer)是一种缓冲包,可以添加自动读取和写入偏移跟踪,字符串操作,数据插入等功能.

## 安装

```sh
npm install smart-buffer
```

也可以使用：`pnpm add smart-buffer`、`yarn add smart-buffer`、`bun add smart-buffer`

## README

# 智能缓冲器 [![Build Status](https://travis-ci.org/JoshGlazebrook/smart-buffer.svg?branch=master)](https://travis-ci.org/JoshGlazebrook/smart-buffer) [![Coverage Status](https://coveralls.io/repos/github/JoshGlazebrook/smart-buffer/badge.svg?branch=master)](https://coveralls.io/github/JoshGlazebrook/smart-buffer?branch=master)

智能缓冲器(Smart-buffer)是一种缓冲包,可以添加自动读取和写入偏移跟踪,字符串操作,数据插入等功能.

![stats](https://nodei.co/npm/smart-buffer.png?downloads=true&downloadRank=true&stars=true "stats")

**关键特性**数字 :

-   代理所有缓冲写入和读取函数
-   跟踪读取和写入自动抵消
-   视需要增加内部缓冲
-   有用的字符串操作 。 (不终止字符串)
-   允许在缓冲器中的特定点插入值
-   已建入类型脚本
-   提供的定义类型
-   浏览器支持( 使用 Webpack/ Browserify)
-   全面测试

**所需资源**数字 :

-   此时已支持Node v4.0+. (2.0前的版本将在0.10节点工作)

## V4. 0 的中断更改

-   旧建筑师模式被完全去除. 现在需要使用 SmartBuffer.from XXX () 工厂构造器.
-   已删除倒带( ) 、 跳过( ) 、 移动 To( ) 。 (见 [页:1](https://npmcn.com/package/smart-buffer/#readme-offsets)(中文(简体) )
-   内部私有属性现在前加下划线( )
-   **全体** 写入xxx () 给予抵消的方法 **覆盖数据** 而不是插入。 (见 [写入 vs 插入](https://npmcn.com/package/smart-buffer/#readme-write-vs-insert)(中文(简体) )
-   插入 XXX () 方法已添加到您想要插入特定偏移时的数据( 这取代了在提供偏移时写入的旧行为)

## 寻找v3docs?

3版及先前的遗留文件 [这里](https://github.com/JoshGlazebrook/smart-buffer/blob/master/docs/README_v3.md)。 。 。 .

## 安装中 :

`yarn add smart-buffer`

或者说

`npm install smart-buffer`

注:已公布的国家预防机制包包括已建成的Javascript图书馆. 如果您复制了此 repo并希望手动构建库:

`npm run build`

## 使用智能缓冲器

```javascript
// Javascript
const SmartBuffer = require('smart-buffer').SmartBuffer;

// Typescript
import { SmartBuffer, SmartBufferOptions} from 'smart-buffer';
```

### 简单示例

构建一个使用以下协议规格的包 :

`[PacketType:2][PacketLength:2][Data:XX]`

要使用香草缓冲舱来构建这个包,你必须事先计算出数据有效载荷的长度。 您还需要跟踪当前缓冲器中的“ cursor” 位置, 以便您在正确的位置写下所有文件 。 有了聪明的缓冲器 你不必做这些事.

```javascript
function createLoginPacket(username, password, age, country) {
    const packet = new SmartBuffer();
    packet.writeUInt16LE(0x0060); // Some packet type
    packet.writeStringNT(username);
    packet.writeStringNT(password);
    packet.writeUInt8(age);
    packet.writeStringNT(country);
    packet.insertUInt16LE(packet.length - 2, 2);

    return packet.toBuffer();
}
```

利用上述功能,您现在可以做到这一点:

```javascript
const login = createLoginPacket("Josh", "secret123", 22, "United States");

// <Buffer 60 00 1e 00 4a 6f 73 68 00 73 65 63 72 65 74 31 32 33 00 16 55 6e 69 74 65 64 20 53 74 61 74 65 73 00>
```

注意到 `[PacketLength:2]` 数值(1e 00)被插入到第2位.

阅读上面我们创建的软件包同样容易:

```javascript

const reader = SmartBuffer.fromBuffer(login);

const logininfo = {
    packetType: reader.readUInt16LE(),
    packetLength: reader.readUInt16LE(),
    username: reader.readStringNT(),
    password: reader.readStringNT(),
    age: reader.readUInt8(),
    country: reader.readStringNT()
};

/*
{
    packetType: 96, (0x0060)
    packetLength: 30,
    username: 'Josh',
    password: 'secret123',
    age: 22,
    country: 'United States'
}
*/
```

## 写入 vs 插入

在之前的SmartBuffer版本中,.write XXX(值,平分)调用在提供抵消时会插入数据. 在第四版中,这将覆盖相抵位置的数据。 要插入数据,现在有对应的XXX(价值,相抵)方法.

**智能缓冲 v3**数字 :

```javascript
const buff = SmartBuffer.fromBuffer(new Buffer([1,2,3,4,5,6]));
buff.writeInt8(7, 2);
console.log(buff.toBuffer())

// <Buffer 01 02 07 03 04 05 06>
```

**智能缓冲 v4**数字 :

```javascript
const buff = SmartBuffer.fromBuffer(new Buffer([1,2,3,4,5,6]));
buff.writeInt8(7, 2);
console.log(buff.toBuffer());

// <Buffer 01 02 07 04 05 06>
```

插入时应当使用:

```javascript
const buff = SmartBuffer.fromBuffer(new Buffer([1,2,3,4,5,6]));
buff.insertInt8(7, 2);
console.log(buff.toBuffer());

// <Buffer 01 02 07 03 04 05 06>
```

**说明:** 插入/写入当前所跟踪的内部缓冲器以外的位置, 您的偏移会为零 .

## 构建智能缓冲器

有几种不同的构建智能缓冲实例的方法.

```javascript
// Creating SmartBuffer from existing Buffer
const buff = SmartBuffer.fromBuffer(buffer); // Creates instance from buffer. (Uses default utf8 encoding)
const buff = SmartBuffer.fromBuffer(buffer, 'ascii'); // Creates instance from buffer with ascii encoding for strings.

// Creating SmartBuffer with specified internal Buffer size. (Note: this is not a hard cap, the internal buffer will grow as needed).
const buff = SmartBuffer.fromSize(1024); // Creates instance with internal Buffer size of 1024.
const buff = SmartBuffer.fromSize(1024, 'utf8'); // Creates instance with internal Buffer size of 1024, and utf8 encoding for strings.

// Creating SmartBuffer with options object. This one specifies size and encoding.
const buff = SmartBuffer.fromOptions({
    size: 1024,
    encoding: 'ascii'
});

// Creating SmartBuffer with options object. This one specified an existing Buffer.
const buff = SmartBuffer.fromOptions({
    buff: buffer
});

// Creating SmartBuffer from a string.
const buff = SmartBuffer.fromBuffer(Buffer.from('some string', 'utf8'));

// Just want a regular SmartBuffer with all default options?
const buff = new SmartBuffer();
```

# Api 参考 :

**说明:** SmartBuffer被完整地记录了 Typescript 定义以及 jsdocs , 所以您最喜欢的编辑器/ IDE 将具有智能感 .

**目录**

1.  [构造](https://npmcn.com/package/smart-buffer/#readme-constructing)
2.  **数字**
    1.  [整数](https://npmcn.com/package/smart-buffer/#readme-integers)
    2.  [浮点](https://npmcn.com/package/smart-buffer/#readme-floating-point-numbers)
3.  **字符串**
    1.  [字符串](https://npmcn.com/package/smart-buffer/#readme-strings)
    2.  [无效终止字符串](https://npmcn.com/package/smart-buffer/#readme-null-terminated-strings)
4.  [缓冲](https://npmcn.com/package/smart-buffer/#readme-buffers)
5.  [减值](https://npmcn.com/package/smart-buffer/#readme-offsets)
6.  [其它](https://npmcn.com/package/smart-buffer/#readme-other)

## 构造

### 构造器( )

### 构造器(\[选项\])

-   `options` _{SmartBuffer 选项}_ 用于构建智能缓冲器的可选选项对象 .

实例:

```javascript
const buff = new SmartBuffer();
const buff = new SmartBuffer({
    size: 1024,
    encoding: 'ascii'
});
```

### 类方法: 从 Buffer( 缓冲\[, 编码\] )

-   `buffer` _{_ 缓冲实例来包装.
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的字符串编码 . `Default: 'utf8'`

实例:

```javascript
const someBuffer = Buffer.from('some string');
const buff = SmartBuffer.fromBuffer(someBuffer); // Defaults to utf8
const buff = SmartBuffer.fromBuffer(someBuffer, 'ascii');
```

### 类方法: 从Size(大小\[,编码\])

-   `size` _{数目}_ 将内部缓冲器初始化的大小.
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的字符串编码 . `Default: 'utf8'`

实例:

```javascript
const buff = SmartBuffer.fromSize(1024); // Defaults to utf8
const buff = SmartBuffer.fromSize(1024, 'ascii');
```

### 类方法: 从选项( 选项)

-   `options` _{SmartBuffer 选项}_ 缓冲实例来包装.

```typescript
interface SmartBufferOptions {
    encoding?: BufferEncoding; // Defaults to utf8
    size?: number; // Defaults to 4096
    buff?: Buffer;
}
```

实例:

```javascript
const buff = SmartBuffer.fromOptions({
    size: 1024
};
const buff = SmartBuffer.fromOptions({
    size: 1024,
    encoding: 'utf8'
});
const buff = SmartBuffer.fromOptions({
    encoding: 'utf8'
});

const someBuff = Buffer.from('some string', 'utf8');
const buff = SmartBuffer.fromOptions({
    buffer: someBuff,
    encoding: 'utf8'
});
```

## 整数

### buff.readInt8(\[抵销\])

### buff.readUInt8(\[抵销\])

-   `offset` _{数目}_ 可选位置开始读取数据 . **默认**数字 : `Auto managed offset`
-   回返 _{数目}_

读取一个 Int8 值 .

### buff.readInt16BE(\[抵销\])

### buff.readInt16LE(\[被抵消\])

### buff.readUInt16BE(\[抵销\])

### buff.readUInt16LE(\[抵销\])

-   `offset` _{数目}_ 可选位置开始读取数据 . **默认**数字 : `Auto managed offset`
-   回返 _{数目}_

读取十六位整数值.

### buff.readInt32BE(\[抵销\])

### buff.readInt32LE(\[抵销\])

### buff.readUInt32BE(\[抵销\])

### buff.readUInt32LE(\[抵销\])

-   `offset` _{数目}_ 可选位置开始读取数据 . **默认**数字 : `Auto managed offset`
-   回返 _{数目}_

读取32位整数值 .

### buff.write Int8(值\[,平分\])

### buff.writeUInt8(值\[,平分\])

-   `value` _{数目}_ 写作的价值.
-   `offset` _{数目}_ 写入此值的可选偏移 . **默认 :** `Auto managed offset`
-   回返 _这个_

写入一个 Int8 值 .

### buff. 插入Int8(值,平分)

### buff. 插入UInt8(值,平方)

-   `value` _{数目}_ 要插入的值 .
-   `offset` _{数目}_ 页:1.
-   回返 _这个_

插入一个 Int8 值.

### buff.write Int16BE( 数值 \[,平分\])

### buff.write Int16LE(值\[,平分\])

### buff.writeUInt16BE(值\[,平分\])

### buff.writeUInt16LE(值\[,平分\])

-   `value` _{数目}_ 写作的价值.
-   `offset` _{数目}_ 写入此值的可选偏移 . **默认 :** `Auto managed offset`
-   回返 _这个_

写入十六位整数值 .

### buff. 插入 Int16BE( 值, 平分)

### buff. 插入Int16LE(值,平分)

### buff. 插入UInt16BE(值,平分)

### buff. 插入UInt16LE(值,平分)

-   `value` _{数目}_ 要插入的值 .
-   `offset` _{数目}_ 页:1.
-   回返 _这个_

插入十六位整数值.

### buff.write Int32BE( 值 \[,平分\])

### buff.write Int32LE(数值\[,平分\])

### buff.writeUInt32BE(值\[,平分\])

### buff.writeUInt32LE(值\[,平分\])

-   `value` _{数目}_ 写作的价值.
-   `offset` _{数目}_ 写入此值的可选偏移 . **默认 :** `Auto managed offset`
-   回返 _这个_

写入32位整数值 .

### buff. 插入Int32BE( 数值, 平方)

### buff. 插入Int32LE(值,平分)

### buff. 插入UInt32BE( 数值, 平方)

### buff.nsertUInt32LE(数值,平分)

-   `value` _{数目}_ 要插入的值 .
-   `offset` _{数目}_ 页:1.
-   回返 _这个_

插入32位整数值.

## 浮点数

### buff.read FloatBE(\[offset\]) (中文(简体) )

### buff.read FloatLE(\[被抵消\])

-   `offset` _{数目}_ 可选位置开始读取数据 . **默认**数字 : `Auto managed offset`
-   回返 _{数目}_

读取浮取值 .

### buff. read DoubleBE(\[被抵消\]) 页面存档备份,存于互联网档案馆

### buff.read DoubleLE(\[抵销\])

-   `offset` _{数目}_ 可选位置开始读取数据 . **默认**数字 : `Auto managed offset`
-   回返 _{数目}_

读取一双值.

### buff.write FloatBE( 值 \[,平分\])

### buff.write FloatLE( 值 \[,平分\])

-   `value` _{数目}_ 写作的价值.
-   `offset` _{数目}_ 写入此值的可选偏移 . **默认 :** `Auto managed offset`
-   回返 _这个_

写出浮点数 .

### buff. 插入FloatBE( 值, 偏移)

### buff. 插入FloatLE( 数值, 偏移)

-   `value` _{数目}_ 要插入的值 .
-   `offset` _{数目}_ 页:1.
-   回返 _这个_

插入浮点值.

### buff.write DoubleBE( 值 \[,平分\])

### buff.write DoubleLE( 数值 \[,平分\])

-   `value` _{数目}_ 写作的价值.
-   `offset` _{数目}_ 写入此值的可选偏移 . **默认 :** `Auto managed offset`
-   回返 _这个_

写出双值 .

### buff. 插入 DoubleBE( 数值, 偏移)

### buff. 插入 DoubleLE( 值, 平分)

-   `value` _{数目}_ 要插入的值 .
-   `offset` _{数目}_ 页:1.
-   回返 _这个_

插入双值.

## 字符串

### buff.readString () (英语)

### buff.readString(大小\[,编码\])

### buff.readString(编码)

-   `size` _{数目}_ 要读取的字节数 . **默认 :** `Reads to the end of the Buffer.`
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的字符串编码 . **默认 :** `utf8`。 。 。 .

读取字符串值.

实例:

```javascript
const buff = SmartBuffer.fromBuffer(Buffer.from('hello there', 'utf8'));
buff.readString(); // 'hello there'
buff.readString(2); // 'he'
buff.readString(2, 'utf8'); // 'he'
buff.readString('utf8'); // 'hello there'
```

### buff.write String( 数值)

### buff.write String( 数值 \[, 平分\])

### buff.write String(值 \[,编码\])

### buff.write String( 值 \[, 偏移 \[, 编码\] \])

-   `value` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要写的字符串值 .
-   `offset` _{数目}_ 将此值写入的偏移 . **默认 :** `Auto managed offset`
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的可选字符串编码 . **默认 :** `utf8`

写入字符串值 .

实例:

```javascript
buff.writeString('hello'); // Auto managed offset
buff.writeString('hello', 2);
buff.writeString('hello', 'utf8') // Auto managed offset
buff.writeString('hello', 2, 'utf8');
```

### buff. 插入String( 值, 相抵 \[, 编码\])

-   `value` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要写的字符串值 .
-   `offset` _{数目}_ 将此值写入的偏移 .
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的可选字符串编码 . **默认 :** `utf8`

插入字符串值.

实例:

```javascript
buff.insertString('hello', 2);
buff.insertString('hello', 2, 'utf8');
```

## 无效终止字符串

### bff.readStringNT () (中文(简体) )

### buff.readStringNT(编码)

-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的字符串编码 . **默认 :** `utf8`。 。 。 .

读取无效终止的字符串值 。 (一无所出即能读取至"缓冲".

实例:

```javascript
const buff = SmartBuffer.fromBuffer(Buffer.from('hello\0 there', 'utf8'));
buff.readStringNT(); // 'hello'

// If we called this again:
buff.readStringNT(); // ' there'
```

### buff.write StringNT( 数值)

### buff.write StringNT(值\[,平分\])

### buff.write StringNT(值\[,编码\])

### buff. write StringNT( 值 \[, 偏移 \[, 编码\] \])

-   `value` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要写的字符串值 .
-   `offset` _{数目}_ 将此值写入的偏移 . **默认 :** `Auto managed offset`
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的可选字符串编码 . **默认 :** `utf8`

写入无效终止的字符串值 .

实例:

```javascript
buff.writeStringNT('hello'); // Auto managed offset   <Buffer 68 65 6c 6c 6f 00>
buff.writeStringNT('hello', 2); // <Buffer 00 00 68 65 6c 6c 6f 00>
buff.writeStringNT('hello', 'utf8') // Auto managed offset
buff.writeStringNT('hello', 2, 'utf8');
```

### buff. 插入 StringNT( 值, 偏移\[, 编码\])

-   `value` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要写的字符串值 .
-   `offset` _{数目}_ 将此值写入的偏移 .
-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要使用的可选字符串编码 . **默认 :** `utf8`

插入无效终止的字符串值.

实例:

```javascript
buff.insertStringNT('hello', 2);
buff.insertStringNT('hello', 2, 'utf8');
```

## 缓冲

### buff.readBuffer( \[长度\] )

-   `length` _{数目}_ 要读入缓冲器的字节数 . **默认 :** `Reads to the end of the Buffer`

读取指定大小的缓冲.

### buff.write Buffer( 值 \[,平分\])

-   `value` _{_ 要写入的缓冲值 .
-   `offset` _{数目}_ 将值写入的可选偏移 . **默认 :** `Auto managed offset`

### buff. 插入缓冲器( 数值, 平分)

-   `value` _{_ 要写入的缓冲值 .
-   `offset` _{数目}_ 将值写入的偏移 .

### buff. read BuffernT () (英语)

读取无效终止的缓冲器 .

### buff.write BuffernT( 值 \[, 平分\])

-   `value` _{_ 要写入的缓冲值 .
-   `offset` _{数目}_ 将值写入的可选偏移 . **默认 :** `Auto managed offset`

写一个无效终止的缓冲器 .

### buff. 插入BuffernT( 数值, 偏移)

-   `value` _{_ 要写入的缓冲值 .
-   `offset` _{数目}_ 将值写入的偏移 .

插入已终止的缓冲 .

## 减值

### buff.readOffset (英语)

### buff.readOffset(抵消) (减法)

-   `offset` _{数目}_ 将新值改为平移值.
-   回返情况: `The current read offset`

获取或设置当前读取的偏移 .

实例:

```javascript
const currentOffset = buff.readOffset; // 5

buff.readOffset = 10;

console.log(buff.readOffset) // 10
```

### buff. writeOffset (英语)

### buff.write offset( 抵销)

-   `offset` _{数目}_ 新写值相抵以设置 .
-   回返情况: `The current write offset`

获取或设置当前写入偏移 .

实例:

```javascript
const currentOffset = buff.writeOffset; // 5

buff.writeOffset = 10;

console.log(buff.writeOffset) // 10
```

### buff.en编码

### buff.en编码(编码)

-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 要设置的新字符串编码 .
-   回返情况: `The current string encoding`

获取或设置当前字符串编码 .

实例:

```javascript
const currentEncoding = buff.encoding; // 'utf8'

buff.encoding = 'ascii';

console.log(buff.encoding) // 'ascii'
```

## 其它

### buff. clear () (中文(简体) )

清除并重置 SmartBuffer 实例 .

### 保留( )

-   回返 `Remaining data left to be read`

获取所剩字节数待读.

### 内部缓冲

-   回返情况: _{_

获取内部管理的缓冲器( 包含未管理的数据) .

实例:

```javascript
const buff = SmartBuffer.fromSize(16);
buff.writeString('hello');
console.log(buff.InternalBuffer); // <Buffer 68 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00>
```

### buff. to Buffer () (英语)

-   回返情况: _{_

获得一个内部管理的缓冲实例。 (仅包括管理下的数据)

实例:

```javascript
const buff = SmartBuffer.fromSize(16);
buff.writeString('hello');
console.log(buff.toBuffer()); // <Buffer 68 65 6c 6c 6f>
```

### buff.to String(\[编码\])

-   `encoding` _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_ 转换为字符串时使用的字符串编码 . **默认 :** `utf8`
-   回返 _{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你来干什么_

获得智能缓冲中所有数据的字符串表示.

### buff.dstroy () (英语)

摧毁 SmartBuffer 实例 .

## 许可证

这项工作根据以下条例获得许可: [麻省理工学院许可证](http://en.wikipedia.org/wiki/MIT_License)。 。 。 .

## 常见问题

### smart-buffer 是什么？

智能缓冲器\(Smart-buffer\)是一种缓冲包,可以添加自动读取和写入偏移跟踪,字符串操作,数据插入等功能\.

### 如何安装 smart-buffer？

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

### smart-buffer 支持 TypeScript 吗？

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

### smart-buffer 支持 ESM 还是 CommonJS？

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

### smart-buffer 需要什么版本的 Node\.js？

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

### smart-buffer 可以商用吗？

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

### smart-buffer 的下载量有多少？

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

### smart-buffer 还在维护吗？

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

