From 0817ff8a73e411adbd431a8461fe955a216a2fed Mon Sep 17 00:00:00 2001 From: bi-hu Date: Fri, 30 Dec 2022 14:36:58 +0800 Subject: [PATCH] Modify the data about buffer Signed-off-by: bi-hu https://gitee.com/openharmony/docs/issues/I67V72 --- .../reference/apis/js-apis-buffer.md | 419 +++++++++--------- .../reference/apis/js-apis-lightweightmap.md | 8 +- .../reference/apis/js-apis-lightweightset.md | 2 +- .../reference/apis/js-apis-linkedlist.md | 2 +- .../reference/apis/js-apis-list.md | 6 +- .../reference/apis/js-apis-plainarray.md | 8 +- .../reference/apis/js-apis-url.md | 8 +- 7 files changed, 230 insertions(+), 223 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-buffer.md b/zh-cn/application-dev/reference/apis/js-apis-buffer.md index 33f6d16e90..3395c225e3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-buffer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-buffer.md @@ -1,11 +1,12 @@ # @ohos.buffer (Buffer) -> **说明:** -> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +Buffer对象用于表示固定长度的字节序列,是专门存放二进制数据的缓存区。 -Buffer对象用于表示固定长度的字节序列,是专门存放二进制数据的缓存区。 +**推荐使用场景:** 可用于处理大量二进制数据,图片处理、文件接收上传等。 -**推荐使用场景:** 可用于处理大量二进制数据,处理图片、文件接收上传等等 +> **说明:** +> +> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 @@ -21,29 +22,27 @@ import buffer from '@ohos.buffer'; | 编码格式 | 说明 | | ------- | -------------------- | -| ascii | 表示ascii格式。 | -| utf8 | 表示utf8格式。 | -| utf-8 | 表示utf8格式。 | -| utf16le | 表示utf16小端序格式。 | -| ucs2 | 表示utf16小端序格式。 | -| ucs-2 | 表示utf16小端序格式。 | -| base64 | 表示base64格式。 | -| base64url | 表示base64格式。 | -| latin1 | 表示ascii格式。 | -| binary | 表示二进制格式。 | -| hex | 表示十六进制格式。 | - -## Buffer +| 'ascii' | 表示ascii格式,不区分大小写。 | +| 'utf8' | 表示utf8格式,不区分大小写。 | +| 'utf-8' | 表示utf8格式,不区分大小写。 | +| 'utf16le' | 表示utf16小端序格式,不区分大小写。 | +| 'ucs2' | 表示utf16小端序格式,不区分大小写。 | +| 'ucs-2' | 表示utf16小端序格式,不区分大小写。 | +| 'base64' | 表示base64格式,不区分大小写。 | +| 'base64url' | 表示base64格式,不区分大小写。 | +| 'latin1' | 表示ascii格式,不区分大小写。 | +| 'binary' | 表示二进制格式,不区分大小写。 | +| 'hex' | 表示十六进制格式,不区分大小写。 | -### 属性 +## 属性 **系统能力:** SystemCapability.Utils.Lang | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| length | number | 是 | 否 | buffer的字节长度。 | +| length | number | 是 | 否 | Buffer对象的字节长度。 | | buffer | ArrayBuffer | 是 | 否 | ArrayBuffer对象。 | -| byteOffset | number | 是 | 否 | 当前buffer所在内存池的偏移量。 | +| byteOffset | number | 是 | 否 | 当前Buffer所在内存池的偏移量。 | **错误码:** @@ -65,11 +64,11 @@ console.log(JSON.stringify(new Uint8Array(arrayBuffer))); console.log(JSON.stringify(buf.byteOffset)); ``` -### alloc +## buffer.alloc alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer -创建`size`个字节长度的Buffer实例,并初始化。 +创建一定字节长度的Buffer对象,并初始化。 **系统能力:** SystemCapability.Utils.Lang @@ -77,15 +76,15 @@ alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| size | number | 是 | 指定的Buffer实例长度,单位:字节。 | -| fill | string \| Buffer \| number | 否 | 预填充的值,默认值: 0 | -| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码方式(当`fill`为string时,才有意义)。 默认值: 'utf-8' | +| size | number | 是 | 指定的Buffer对象长度,单位:字节。 | +| fill | string \| Buffer \| number | 否 | 填充至新缓存区的值,默认值: 0。 | +| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码格式(当`fill`为string时,才有意义)。 默认值: 'utf-8'。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 带初始化的Buffer实例。 | +| Buffer | 返回一个Buffer对象。 | **示例:** @@ -97,12 +96,12 @@ let buf2 = buffer.alloc(5, 'a'); let buf3 = buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64'); ``` -### allocUninitializedFromPool +## buffer.allocUninitializedFromPool allocUninitializedFromPool(size: number): Buffer -创建指定大小的未被初始化Buffer实例。内存从缓冲池分配。 -创建的Buffer的内容未知,需要使用fill()函数来初始化Buffer实例。 +创建指定大小未被初始化的Buffer对象。内存从缓冲池分配。 +创建的Buffer的内容未知,需要使用[buffer.fill](#bufferfill)函数来初始化Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -110,7 +109,7 @@ allocUninitializedFromPool(size: number): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| size | number | 是 | 指定的Buffer实例长度,单位:字节。 | +| size | number | 是 | 指定的Buffer对象长度,单位:字节。 | **返回值:** @@ -127,11 +126,12 @@ let buf = buffer.allocUninitializedFromPool(10); buf.fill(0); ``` -### allocUninitialized +## buffer.allocUninitialized allocUninitialized(size: number): Buffer -创建指定大小的未被初始化Buffer实例。内存不从缓冲池分配。 +创建指定大小未被初始化的Buffer实例。内存不从缓冲池分配。 +创建的Buffer的内容未知,需要使用[buffer.fill](#bufferfill)函数来初始化Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -139,7 +139,7 @@ allocUninitialized(size: number): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| size | number | 是 |指定的Buffer实例长度,单位:字节。 | +| size | number | 是 |指定的Buffer对象长度,单位:字节。 | **返回值:** @@ -156,11 +156,11 @@ let buf = buffer.allocUninitialized(10); buf.fill(0); ``` -### byteLength +## buffer.byteLength byteLength(string: string | Buffer | TypedArray | DataView | ArrayBuffer | SharedArrayBuffer, encoding?: BufferEncoding): number -根据不同的编码方法,返回字符串的字节数。 +根据不同的编码方法,返回指定字符串的字节数。 **系统能力:** SystemCapability.Utils.Lang @@ -169,13 +169,13 @@ byteLength(string: string | Buffer | TypedArray | DataView | ArrayBuffer | Share | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | string | string \| Buffer \| TypedArray \| DataView \| ArrayBuffer \| SharedArrayBuffer | 是 | 指定字符串。 | -| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码方式。 默认值: 'utf-8' | +| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码格式。 默认值: 'utf-8'。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| number | 返回字符串的字节数 | +| number | 返回指定字符串的字节数。 | **示例:** @@ -187,11 +187,11 @@ console.log(`${str}: ${str.length} characters, ${buffer.byteLength(str, 'utf-8') // 打印: ½ + ¼ = ¾: 9 characters, 12 bytes ``` -### compare +## buffer.compare compare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): -1 | 0 | 1 -返回比较buf1和buf2的结果, 通常用于对Buffer实例的数组进行排序。 +返回两个数组的比较结果,通常用于对Buffer对象数组进行排序。 **系统能力:** SystemCapability.Utils.Lang @@ -207,7 +207,7 @@ compare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): -1 | 0 | 1 | 类型 | 说明 | | -------- | -------- | -| -1 \| 0 \| 1 | 如果buf1与buf2相同,则返回0
如果排序时buf1位于buf2之后,则返回1
如果排序时buf1位于buf2之前,则返回-1。 | +| -1 \| 0 \| 1 | 如果buf1与buf2相同,则返回0。
如果排序时buf1位于buf2之后,则返回1。
如果排序时buf1位于buf2之前,则返回-1。 | **示例:** @@ -221,11 +221,11 @@ let res = buf1.compare(buf2); console.log(Number(res).toString()); // 打印 1 ``` -### concat +## buffer.concat concat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer -将`list`中的实例内容复制`totalLength`字节长度到新的Buffer实例中并返回。 +将数组中的内容复制指定字节长度到新的Buffer对象中并返回。 **系统能力:** SystemCapability.Utils.Lang @@ -234,13 +234,13 @@ concat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | list | Buffer[] \| Uint8Array[] | 是 | 实例数组。 | -| totalLength | number | 否 | 需要融合的总字节长度。 | +| totalLength | number | 否 | 需要复制的总字节长度。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 返回新Buffer的实例。 | +| Buffer | 返回新的Buffer对象。 | **错误码:** @@ -261,11 +261,11 @@ let buf = buffer.concat([buf1, buf2]); console.log(buf.toString('hex')); // 3132333461626364 ``` -### from +## buffer.from from(array: number[]): Buffer; -根据指定数组创建新的Buffer实例。 +根据指定数组创建新的Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -279,7 +279,7 @@ from(array: number[]): Buffer; | 类型 | 说明 | | -------- | -------- | -| Buffer | 新的Buffer实例。 | +| Buffer | 新的Buffer对象。 | **示例:** @@ -290,11 +290,11 @@ let buf = buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); console.log(buf.toString('hex')); // 627566666572 ``` -### from +## buffer.from from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer -创建指定长度的与`arrayBuffer`共享内存的Buffer实例 +创建指定长度的与`arrayBuffer`共享内存的Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -304,13 +304,13 @@ from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: | -------- | -------- | -------- | -------- | | arrayBuffer | ArrayBuffer \| SharedArrayBuffer | 是 | 实例对象。 | | byteOffset | number | 否 | 字节偏移量,默认值: 0。 | -| length | number | 否 | 字节长度, 默认值: arrayBuffer.byteLength - byteOffset。 | +| length | number | 否 | 字节长度, 默认值: (arrayBuffer.byteLength - byteOffset)。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 返回一个共享内存的Buffer实例。 | +| Buffer | 返回一个共享内存的Buffer对象。 | **错误码:** @@ -329,11 +329,11 @@ let ab = new ArrayBuffer(10); let buf = buffer.from(ab, 0, 2); ``` -### from +## buffer.from from(buffer: Buffer | Uint8Array): Buffer -创建并复制`buffer`数据到新的Buffer实例并返回。 +创建并复制`buffer`数据到新的Buffer对象并返回。 **系统能力:** SystemCapability.Utils.Lang @@ -341,13 +341,13 @@ from(buffer: Buffer | Uint8Array): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| buffer | Buffer \| Uint8Array | 是 | 实例数据。 | +| buffer | Buffer \| Uint8Array | 是 | 对象数据。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 新的Buffer实例。 | +| Buffer | 新的Buffer对象。 | **示例:** @@ -358,11 +358,11 @@ let buf1 = buffer.from('buffer'); let buf2 = buffer.from(buf1); ``` -### from +## buffer.from from(object: Object, offsetOrEncoding: number | string, length: number): Buffer -根据指定的`object`类型数据,创建新的Buffer实例。 +根据指定的`object`类型数据,创建新的Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -370,29 +370,29 @@ from(object: Object, offsetOrEncoding: number | string, length: number): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| object | Object | 是 | 支持Symbol.toPrimitive或valueOf()的对象 | -| offsetOrEncoding | number \| string | 是 | 字节偏移量或编码。 | +| object | Object | 是 | 支持Symbol.toPrimitive或valueOf()的对象。 | +| offsetOrEncoding | number \| string | 是 | 字节偏移量或编码格式。 | | length | number | 是 | 字节长度。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 新的Buffer实例。 | +| Buffer | 返回新的Buffer对象。 | **示例:** ```ts import buffer from '@ohos.buffer'; -let buf = buffer.from(new String('this is a test')); +let buf = buffer.from(new String('this is a test'), 'utf8', 14); ``` -### from +## buffer.from from(string: String, encoding?: BufferEncoding): Buffer -根据指定编码格式的字符串,创建新的Buffer实例。 +根据指定编码格式的字符串,创建新的Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -407,7 +407,7 @@ from(string: String, encoding?: BufferEncoding): Buffer | 类型 | 说明 | | -------- | -------- | -| Buffer | 新的Buffer实例。 | +| Buffer | 返回新的Buffer对象。 | **示例:** @@ -422,7 +422,7 @@ console.log(buf2.toString()); ``` -### isBuffer +## buffer.isBuffer isBuffer(obj: Object): boolean @@ -454,7 +454,7 @@ buffer.isBuffer([]); // false buffer.isBuffer(new Uint8Array(1024)); // false ``` -### isEncoding +## buffer.isEncoding isEncoding(encoding: string): boolean @@ -472,7 +472,7 @@ isEncoding(encoding: string): boolean | 类型 | 说明 | | -------- | -------- | -| boolean | true或者false。 | +| boolean | 是支持的编码格式返回true,反之则返回false。 | **示例:** @@ -485,11 +485,11 @@ console.log(buffer.isEncoding('utf/8').toString()); // 打印: false console.log(buffer.isEncoding('').toString()); // 打印: false ``` -### compare +## buffer.compare compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1 -`this`实例对象与`target`实例对象进行比较,返回buf在排序中的顺序,-1:前排序,0:与buf相同,1:后排序。 +当前Buffer对象与目标Buffer对象进行比较,并返回Buffer在排序中的顺序结果。 **系统能力:** SystemCapability.Utils.Lang @@ -499,15 +499,15 @@ compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, s | -------- | -------- | -------- | -------- | | target | Buffer \| Uint8Array | 是 | 要比较的实例对象。 | | targetStart | number | 否 | `target`实例中开始的偏移量。 默认值: 0。 | -| targetEnd | number | 否 | `target`实例中结束的偏移量(不包括本身)。 默认值: target.length。 | +| targetEnd | number | 否 | `target`实例中结束的偏移量(不包含结束位置)。 默认值: 目标对象的字节长度。 | | sourceStart | number | 否 | `this`实例中开始的偏移量。 默认值: 0。 | -| sourceEnd | number | 否 | `this`实例中结束的偏移量(不包括本身)。 默认值: buf.length。 | +| sourceEnd | number | 否 | `this`实例中结束的偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| number | 比较结果。-1:前排序,0:与buf相同,1:后排序。 | +| number | 返回比较结果。-1:当前排列在目标前,0:当前与目标相同,1:当前排列在目标后。 | **错误码:** @@ -530,7 +530,7 @@ console.log(buf1.compare(buf2, 0, 6, 4).toString()); // 打印: -1 console.log(buf1.compare(buf2, 5, 6, 5).toString()); // 打印: 1 ``` -### copy +## buffer.copy copy(target: Buffer| Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number @@ -545,7 +545,7 @@ copy(target: Buffer| Uint8Array, targetStart?: number, sourceStart?: number, sou | target | Buffer \| Uint8Array | 是 | 要复制到的Buffer或Uint8Array实例。 | | targetStart | number | 否 | `target`实例中开始写入的偏移量。 默认值: 0。 | | sourceStart | number | 否 | `this`实例中开始复制的偏移量。 默认值: 0。 | -| sourceEnd | number | 否 | `this`实例中结束复制的偏移量(不包括)。 默认值: buf.length。 | +| sourceEnd | number | 否 | `this`实例中结束复制的偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | **返回值:** @@ -578,7 +578,7 @@ console.log(buf2.toString('ascii', 0, 25)); // 打印: !!!!!!!!qrst!!!!!!!!!!!!! ``` -### entries +## buffer.entries entries(): IterableIterator<[number, number]> @@ -586,6 +586,13 @@ entries(): IterableIterator<[number, number]> **系统能力:** SystemCapability.Utils.Lang +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| number | 表示迭代器的key值。 | +| number | 表示迭代器的value值。 | + **示例:** ```ts @@ -597,7 +604,7 @@ for (let pair of buf.entries()) { } ``` -### equals +## buffer.equals equals(otherBuffer: Uint8Array | Buffer): boolean @@ -630,11 +637,11 @@ console.log(buf1.equals(buf2).toString()); // 打印: true console.log(buf1.equals(buf3).toString()); // 打印: false ``` -### fill +## buffer.fill fill(value: string | Buffer | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): Buffer -用`value`填充`this`实例指定位置的数据,默认为循环填充,并返回填充后的Buffer实例。 +用`value`填充当前对象指定位置的数据,默认为循环填充,并返回填充后的Buffer对象。 **系统能力:** SystemCapability.Utils.Lang @@ -644,14 +651,14 @@ fill(value: string | Buffer | Uint8Array | number, offset?: number, end?: number | -------- | -------- | -------- | -------- | | value | string \| Buffer \| Uint8Array \| number | 是 | 用于填充的值。 | | offset | number | 否 | 起始偏移量。 默认值: 0。 | -| end | number | 否 | 结束偏移量(不包括在内)。 默认值: buf.length。 | +| end | number | 否 | 结束偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | | encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式(`value`为string才有意义)。 默认值: 'utf-8'。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 填充后的Buffer实例。 | +| Buffer | 返回一个填充后的Buffer对象。 | **错误码:** @@ -671,7 +678,7 @@ console.log(b.toString()); ``` -### includes +## buffer.includes includes(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): boolean @@ -703,11 +710,11 @@ console.log(buf.includes('this').toString()); // 打印: true console.log(buf.includes('be').toString()); // 打印: false ``` -### indexOf +## buffer.indexOf indexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number -查找`this`实例中第一次出现`value`的索引,如果不包含`value`,则为-1 +查找当前对象中第一次出现`value`的索引,如果不包含`value`,则为-1。 **系统能力:** SystemCapability.Utils.Lang @@ -715,7 +722,7 @@ indexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encod | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | string \| number \| Buffer \| Uint8Array | 是 | 要搜索的内容。 | +| value | string \| number \| Buffer \| Uint8Array | 是 | 要查找的内容。 | | byteOffset | number | 否 | 字节偏移量。 如果为负数,则从末尾开始计算偏移量。 默认值: 0。 | | encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式。 默认值: 'utf-8'。 | @@ -735,11 +742,11 @@ console.log(buf.indexOf('this').toString()); // 打印: 0 console.log(buf.indexOf('is').toString()); // 打印: 2 ``` -### keys +## buffer.keys keys(): IterableIterator<number> -返回一个包含key值的迭代器 +返回一个包含key值的迭代器。 **系统能力:** SystemCapability.Utils.Lang @@ -747,7 +754,7 @@ keys(): IterableIterator<number> | 类型 | 说明 | | -------- | -------- | -| IterableIterator<number> | 迭代器。 | +| IterableIterator<number> | 返回一个包含key值的迭代器。 | **示例:** @@ -760,7 +767,7 @@ for (const key of buf.keys()) { } ``` -### lastIndexOf +## buffer.lastIndexOf lastIndexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number @@ -793,7 +800,7 @@ console.log(buf.lastIndexOf('buffer').toString()); // 打印: 17 ``` -### readBigInt64BE +## buffer.readBigInt64BE readBigInt64BE(offset?: number): bigint @@ -834,7 +841,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeBigInt64BE(0x0102030405060708n, 0); ``` -### readBigInt64LE +## buffer.readBigInt64LE readBigInt64LE(offset?: number): bigint @@ -875,7 +882,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeBigInt64BE(0x0102030405060708n, 0); ``` -### readBigUInt64BE +## buffer.readBigUInt64BE readBigUInt64BE(offset?: number): bigint @@ -916,7 +923,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` -### readBigUInt64LE +## buffer.readBigUInt64LE readBigUInt64LE(offset?: number): bigint @@ -957,7 +964,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` -### readDoubleBE +## buffer.readDoubleBE readDoubleBE(offset?: number): number @@ -997,7 +1004,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeDoubleBE(123.456, 0); ``` -### readDoubleLE +## buffer.readDoubleLE readDoubleLE(offset?: number): number @@ -1037,7 +1044,7 @@ let buf1 = buffer.allocUninitializedFromPool(8); buf1.writeDoubleLE(123.456, 0); ``` -### readFloatBE +## buffer.readFloatBE readFloatBE(offset?: number): number @@ -1077,7 +1084,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeFloatBE(0xcabcbcbc, 0); ``` -### readFloatLE +## buffer.readFloatLE readFloatLE(offset?: number): number @@ -1117,7 +1124,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeFloatLE(0xcabcbcbc, 0); ``` -### readInt8 +## buffer.readInt8 readInt8(offset?: number): number @@ -1158,7 +1165,7 @@ let buf1 = buffer.allocUninitializedFromPool(2); buf1.writeInt8(0x12); ``` -### readInt16BE +## buffer.readInt16BE readInt16BE(offset?: number): number @@ -1198,11 +1205,11 @@ let buf1 = buffer.alloc(2); buf1.writeInt16BE(0x1234, 0); ``` -### readInt16LE +## buffer.readInt16LE readInt16LE(offset?: number): number -从指定的`offset`处读取有符号的小端序16位整数 +从指定的`offset`处读取有符号的小端序16位整数。 **系统能力:** SystemCapability.Utils.Lang @@ -1238,11 +1245,11 @@ let buf1 = buffer.alloc(2); buf1.writeInt16BE(0x1234, 0); ``` -### readInt32BE +## buffer.readInt32BE readInt32BE(offset?: number): number -从指定的`offset`处读取有符号的大端序32位整数 +从指定的`offset`处读取有符号的大端序32位整数。 **系统能力:** SystemCapability.Utils.Lang @@ -1278,11 +1285,11 @@ let buf1 = buffer.alloc(4); buf1.writeInt32BE(0x12345678, 0); ``` -### readInt32LE +## buffer.readInt32LE readInt32LE(offset?: number): number -从指定的`offset`处读取有符号的小端序32位整数 +从指定的`offset`处读取有符号的小端序32位整数。 **系统能力:** SystemCapability.Utils.Lang @@ -1318,7 +1325,7 @@ let buf1 = buffer.alloc(4); buf1.writeInt32BE(0x12345678, 0); ``` -### readIntBE +## buffer.readIntBE readIntBE(offset: number, byteLength: number): number @@ -1362,7 +1369,7 @@ buf1.writeIntBE(0x123456789011, 0, 6); ``` -### readIntLE +## buffer.readIntLE readIntLE(offset: number, byteLength: number): number @@ -1404,7 +1411,7 @@ let buf1 = buffer.allocUninitializedFromPool(6); buf1.writeIntLE(0x123456789011, 0, 6); ``` -### readUInt8 +## buffer.readUInt8 readUInt8(offset?: number): number @@ -1446,7 +1453,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUInt8(0x42); ``` -### readUInt16BE +## buffer.readUInt16BE readUInt16BE(offset?: number): number @@ -1488,7 +1495,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUInt16BE(0x1234, 0); ``` -### readUInt16LE +## buffer.readUInt16LE readUInt16LE(offset?: number): number @@ -1530,7 +1537,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUInt16LE(0x1234, 0); ``` -### readUInt32BE +## buffer.readUInt32BE readUInt32BE(offset?: number): number @@ -1571,7 +1578,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUInt32BE(0x12345678, 0); ``` -### readUInt32LE +## buffer.readUInt32LE readUInt32LE(offset?: number): number @@ -1612,7 +1619,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUInt32LE(0x12345678, 0); ``` -### readUIntBE +## buffer.readUIntBE readUIntBE(offset: number, byteLength: number): number @@ -1654,7 +1661,7 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUIntBE(0x13141516, 0, 4); ``` -### readUIntLE +## buffer.readUIntLE readUIntLE(offset: number, byteLength: number): number @@ -1696,11 +1703,11 @@ let buf1 = buffer.allocUninitializedFromPool(4); buf1.writeUIntLE(0x13141516, 0, 4); ``` -### subarray +## buffer.subarray subarray(start?: number, end?: number): Buffer -截取指定位置的`this`实例并返回。 +截取当前对象指定位置的数据并返回。 **系统能力:** SystemCapability.Utils.Lang @@ -1709,13 +1716,13 @@ subarray(start?: number, end?: number): Buffer | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | start | number | 否 | 截取开始位置。 默认值: 0。 | -| end | number | 否 | 截取结束位置(不包括在内)。 默认值: buf.length。 | +| end | number | 否 | 截取结束位置(不包含结束位置)。 默认值: 当前对象的字节长度。 | **返回值:** | 类型 | 说明 | | -------- | -------- | -| Buffer | 新的Buffer实例。 | +| Buffer | 返回新的Buffer对象。 | **示例:** @@ -1732,11 +1739,11 @@ console.log(buf2.toString('ascii', 0, buf2.length)); // 打印: abc ``` -### swap16 +## buffer.swap16 swap16(): Buffer -将`this`实例解释为无符号的16位整数数组,并就地交换字节顺序。 +将当前对象解释为无符号的16位整数数组,并交换字节顺序。 **系统能力:** SystemCapability.Utils.Lang @@ -1767,11 +1774,11 @@ buf1.swap16(); console.log(buf1.toString('hex')); // 打印: 0201040306050807 ``` -### swap32 +## buffer.swap32 swap32(): Buffer -将`this`实例解释为无符号的32位整数数组,并就地交换字节顺序 +将当前对象解释为无符号的32位整数数组,并交换字节顺序。 **系统能力:** SystemCapability.Utils.Lang @@ -1780,7 +1787,7 @@ swap32(): Buffer | 类型 | 说明 | | -------- | -------- | -| Buffer | 交换之后的Buffer实例。 | +| Buffer | 交换之后的Buffer对象。 | **错误码:** @@ -1802,11 +1809,11 @@ buf1.swap32(); console.log(buf1.toString('hex')); // 打印: 0403020108070605 ``` -### swap64 +## buffer.swap64 swap64(): Buffer -将`this`实例解释为无符号的64位整数数组,并就地交换字节顺序 +将当前对象解释为无符号的64位整数数组,并交换字节顺序。 **系统能力:** SystemCapability.Utils.Lang @@ -1815,7 +1822,7 @@ swap64(): Buffer | 类型 | 说明 | | -------- | -------- | -| Buffer | 交换之后的Buffer实例。 | +| Buffer | 交换之后的Buffer对象。 | **错误码:** @@ -1836,11 +1843,11 @@ buf1.swap64(); console.log(buf1.toString('hex')); // 打印: 0807060504030201 ``` -### toJSON +## buffer.toJSON toJSON(): Object -将buf转为JSON并返回。 +将Buffer转为JSON并返回。 **系统能力:** SystemCapability.Utils.Lang @@ -1862,11 +1869,11 @@ console.log(JSON.stringify(obj)) // 打印: {"type":"Buffer","data":[1,2,3,4,5]} ``` -### toString +## buffer.toString toString(encoding?: string, start?: number, end?: number): string -将`this`实例中指定位置数据转成指定编码格式字符串并返回。 +将当前对象中指定位置数据转成指定编码格式字符串并返回。 **系统能力:** SystemCapability.Utils.Lang @@ -1876,7 +1883,7 @@ toString(encoding?: string, start?: number, end?: number): string | -------- | -------- | -------- | -------- | | encoding | string | 否 | 字符编码格式。 默认值: 'utf-8'。 | | start | number | 否 | 开始位置。 默认值: 0。 | -| end | number | 否 | 结束位置。 默认值: buf.length。 | +| end | number | 否 | 结束位置。 默认值: Buffer.length。 | **返回值:** @@ -1897,7 +1904,7 @@ console.log(buf1.toString('utf-8')); // 打印: abcdefghijklmnopqrstuvwxyz ``` -### values +## buffer.values values(): IterableIterator<number> @@ -1922,11 +1929,11 @@ for (let value of buf1.values()) { } ``` -### write +## buffer.write write(str: string, offset?: number, length?: number, encoding?: string): number -从buf的offset偏移写入指定编码的字符串str,写入的字节长度为length +从Buffer对象的offset偏移写入指定编码的字符串str,写入的字节长度为length。 **系统能力:** SystemCapability.Utils.Lang @@ -1936,7 +1943,7 @@ write(str: string, offset?: number, length?: number, encoding?: string): number | -------- | -------- | -------- | -------- | | str | string | 是 | 要写入Buffer的字符串。 | | offset | number | 否 | 偏移量。 默认值: 0。 | -| length | number | 否 | 最大字节长度。 默认值: (buf.length - offset)。| +| length | number | 否 | 最大字节长度。 默认值: (Buffer.length - offset)。| | encoding | string | 否 | 字符编码。 默认值: 'utf-8'。 | @@ -1968,11 +1975,11 @@ let buffer1 = buffer.alloc(10); let length = buffer1.write('abcd', 8); ``` -### writeBigInt64BE +## buffer.writeBigInt64BE writeBigInt64BE(value: bigint, offset?: number): number -从buf的offset偏移写入有符号的大端序64位BigInt型数据value +从Buffer对象的offset偏移写入有符号的大端序64位BigInt型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -1980,7 +1987,7 @@ writeBigInt64BE(value: bigint, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | bigint | 是 | 写入 buf 的数字。 | +| value | bigint | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2007,11 +2014,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeBigInt64BE(0x0102030405060708n, 0); ``` -### writeBigInt64LE +## buffer.writeBigInt64LE writeBigInt64LE(value: bigint, offset?: number): number -从buf的offset偏移写入有符号的小端序64位BigInt型数据value +从Buffer对象的offset偏移写入有符号的小端序64位BigInt型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2019,7 +2026,7 @@ writeBigInt64LE(value: bigint, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | bigint | 是 | 写入 buf 的数字。 | +| value | bigint | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2046,11 +2053,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeBigInt64LE(0x0102030405060708n, 0); ``` -### writeBigUInt64BE +## buffer.writeBigUInt64BE writeBigUInt64BE(value: bigint, offset?: number): number -从buf的offset偏移写入无符号的大端序64位BigUInt型数据value +从Buffer对象的offset偏移写入无符号的大端序64位BigUInt型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2058,7 +2065,7 @@ writeBigUInt64BE(value: bigint, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | bigint | 是 | 写入 buf 的数字。 | +| value | bigint | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2085,11 +2092,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeBigUInt64BE(0xdecafafecacefaden, 0); ``` -### writeBigUInt64LE +## buffer.writeBigUInt64LE writeBigUInt64LE(value: bigint, offset?: number): number -从buf的offset偏移写入无符号的小端序64位BigUInt型数据value +从Buffer对象的offset偏移写入无符号的小端序64位BigUInt型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2097,7 +2104,7 @@ writeBigUInt64LE(value: bigint, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | bigint | 是 | 写入 buf 的数字。 | +| value | bigint | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2124,11 +2131,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeBigUInt64LE(0xdecafafecacefaden, 0); ``` -### writeDoubleBE +## buffer.writeDoubleBE writeDoubleBE(value: number, offset?: number): number -从buf的offset偏移写入大端序的64位双浮点型数据value +从Buffer对象的offset偏移写入大端序的64位双浮点型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2136,7 +2143,7 @@ writeDoubleBE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2163,11 +2170,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeDoubleBE(123.456, 0); ``` -### writeDoubleLE +## buffer.writeDoubleLE writeDoubleLE(value: number, offset?: number): number -从buf的offset偏移写入小端序的64位双浮点型数据value +从Buffer对象的offset偏移写入小端序的64位双浮点型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2175,7 +2182,7 @@ writeDoubleLE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2202,11 +2209,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeDoubleLE(123.456, 0); ``` -### writeFloatBE +## buffer.writeFloatBE writeFloatBE(value: number, offset?: number): number -从buf的offset偏移写入大端序的32位浮点型数据value +从Buffer对象的offset偏移写入大端序的32位浮点型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2214,7 +2221,7 @@ writeFloatBE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2242,11 +2249,11 @@ buf.writeFloatBE(0xcafebabe, 0); ``` -### writeFloatLE +## buffer.writeFloatLE writeFloatLE(value: number, offset?: number): number -从buf的offset偏移写入小端序的32位浮点型数据value +从Buffer对象的offset偏移写入小端序的32位浮点型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2254,7 +2261,7 @@ writeFloatLE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2281,11 +2288,11 @@ let buf = buffer.allocUninitializedFromPool(8); buf.writeFloatLE(0xcafebabe, 0); ``` -### writeInt8 +## buffer.writeInt8 writeInt8(value: number, offset?: number): number -从buf的offset偏移写入8位有符号整型数据value +从Buffer对象的offset偏移写入8位有符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2293,7 +2300,7 @@ writeInt8(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2322,11 +2329,11 @@ buf.writeInt8(-2, 1); ``` -### writeInt16BE +## buffer.writeInt16BE writeInt16BE(value: number, offset?: number): number -从buf的offset偏移写入大端序的16位有符号整型数据value +从Buffer对象的offset偏移写入大端序的16位有符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2334,7 +2341,7 @@ writeInt16BE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2362,11 +2369,11 @@ buf.writeInt16BE(0x0102, 0); ``` -### writeInt16LE +## buffer.writeInt16LE writeInt16LE(value: number, offset?: number): number -从buf的offset偏移写入小端序的16位有符号整型数据value +从Buffer对象的offset偏移写入小端序的16位有符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2374,7 +2381,7 @@ writeInt16LE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2401,11 +2408,11 @@ let buf = buffer.allocUninitializedFromPool(2); buf.writeInt16LE(0x0304, 0); ``` -### writeInt32BE +## buffer.writeInt32BE writeInt32BE(value: number, offset?: number): number -从buf的offset偏移写入大端序的32位有符号整型数据value +从Buffer对象的offset偏移写入大端序的32位有符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2413,7 +2420,7 @@ writeInt32BE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2441,11 +2448,11 @@ buf.writeInt32BE(0x01020304, 0); ``` -### writeInt32LE +## buffer.writeInt32LE writeInt32LE(value: number, offset?: number): number -从buf的offset偏移写入小端序的32位有符号整型数据value +从Buffer对象的offset偏移写入小端序的32位有符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2453,7 +2460,7 @@ writeInt32LE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2480,11 +2487,11 @@ let buf = buffer.allocUninitializedFromPool(4); buf.writeInt32LE(0x05060708, 0); ``` -### writeIntBE +## buffer.writeIntBE writeIntBE(value: number, offset: number, byteLength: number): number -从buf的offset偏移写入大端序的有符号value数据,value字节长度为byteLength +从Buffer对象的offset偏移写入大端序的有符号value数据,value字节长度为byteLength。 **系统能力:** SystemCapability.Utils.Lang @@ -2492,7 +2499,7 @@ writeIntBE(value: number, offset: number, byteLength: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 是 | 偏移量。 默认值: 0。 | | byteLength | number | 是 | 要写入的字节数。 | @@ -2521,11 +2528,11 @@ buf.writeIntBE(0x1234567890ab, 0, 6); ``` -### writeIntLE +## buffer.writeIntLE writeIntLE(value: number, offset: number, byteLength: number): number -从buf的offset偏移写入小端序的有符号value数据,value字节长度为byteLength +从Buffer对象的offset偏移写入小端序的有符号value数据,value字节长度为byteLength。 **系统能力:** SystemCapability.Utils.Lang @@ -2533,7 +2540,7 @@ writeIntLE(value: number, offset: number, byteLength: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 是 | 偏移量。 默认值: 0。 | | byteLength | number | 是 | 要写入的字节数。 | @@ -2561,11 +2568,11 @@ let buf = buffer.allocUninitializedFromPool(6); buf.writeIntLE(0x1234567890ab, 0, 6); ``` -### writeUInt8 +## buffer.writeUInt8 writeUInt8(value: number, offset?: number): number -从buf的offset偏移写入8位无符号整型数据value +从Buffer对象的offset偏移写入8位无符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2573,7 +2580,7 @@ writeUInt8(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2603,11 +2610,11 @@ buf.writeUInt8(0x23, 2); buf.writeUInt8(0x42, 3); ``` -### writeUInt16BE +## buffer.writeUInt16BE writeUInt16BE(value: number, offset?: number): number -从buf的offset偏移写入大端序的16位无符号整型数据value +从Buffer对象的offset偏移写入大端序的16位无符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2615,7 +2622,7 @@ writeUInt16BE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2643,11 +2650,11 @@ buf.writeUInt16BE(0xdead, 0); buf.writeUInt16BE(0xbeef, 2); ``` -### writeUInt16LE +## buffer.writeUInt16LE writeUInt16LE(value: number, offset?: number): number -从buf的offset偏移写入小端序的16位无符号整型数据value +从Buffer对象的offset偏移写入小端序的16位无符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2655,7 +2662,7 @@ writeUInt16LE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2683,11 +2690,11 @@ buf.writeUInt16LE(0xdead, 0); buf.writeUInt16LE(0xbeef, 2); ``` -### writeUInt32BE +## buffer.writeUInt32BE writeUInt32BE(value: number, offset?: number): number -从buf的offset偏移写入大端序的32位无符号整型数据value +从Buffer对象的offset偏移写入大端序的32位无符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2695,7 +2702,7 @@ writeUInt32BE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数据。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2722,11 +2729,11 @@ let buf = buffer.allocUninitializedFromPool(4); buf.writeUInt32BE(0xfeedface, 0); ``` -### writeUInt32LE +## buffer.writeUInt32LE writeUInt32LE(value: number, offset?: number): number -从buf的offset偏移写入小端序的32位无符号整型数据value +从Buffer对象的offset偏移写入小端序的32位无符号整型数据value。 **系统能力:** SystemCapability.Utils.Lang @@ -2734,7 +2741,7 @@ writeUInt32LE(value: number, offset?: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数字。 | +| value | number | 是 | 写入Buffer对象的数字。 | | offset | number | 否 | 偏移量。 默认值: 0。 | @@ -2761,11 +2768,11 @@ let buf = buffer.allocUninitializedFromPool(4); buf.writeUInt32LE(0xfeedface, 0); ``` -### writeUIntBE +## buffer.writeUIntBE writeUIntBE(value: number, offset: number, byteLength: number): number -从buf的offset偏移写入大端序的无符号value数据,value字节长度为byteLength +从Buffer对象的offset偏移写入大端序的无符号value数据,value字节长度为byteLength。 **系统能力:** SystemCapability.Utils.Lang @@ -2773,7 +2780,7 @@ writeUIntBE(value: number, offset: number, byteLength: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数据。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 是 | 偏移量。 默认值: 0。 | | byteLength | number | 是 | 要写入的字节数。 | @@ -2801,11 +2808,11 @@ let buf = buffer.allocUninitializedFromPool(6); buf.writeUIntBE(0x1234567890ab, 0, 6); ``` -### writeUIntLE +## buffer.writeUIntLE writeUIntLE(value: number, offset: number, byteLength: number): number -从buf的offset偏移写入小端序的无符号value数据,value字节长度为byteLength +从Buffer对象的offset偏移写入小端序的无符号value数据,value字节长度为byteLength。 **系统能力:** SystemCapability.Utils.Lang @@ -2813,7 +2820,7 @@ writeUIntLE(value: number, offset: number, byteLength: number): number | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| value | number | 是 | 写入 buf 的数据。 | +| value | number | 是 | 写入Buffer的数据。 | | offset | number | 是 | 偏移量。 默认值: 0。 | | byteLength | number | 是 | 要写入的字节数。 | @@ -2841,11 +2848,11 @@ let buf = buffer.allocUninitializedFromPool(6); buf.writeUIntLE(0x1234567890ab, 0, 6); ``` -### transcode +## buffer.transcode transcode(source: Buffer | Uint8Array, fromEnc: string, toEnc: string): Buffer -将给定的Buffer或Uint8Array实例从一种字符编码重新编码为另一种 +将给定的Buffer或Uint8Array对象从一种字符编码重新编码为另一种。 **系统能力:** SystemCapability.Utils.Lang @@ -2919,7 +2926,7 @@ arrayBuffer(): Promise<ArrayBuffer> **返回值:** | 类型 | 说明 | | -------- | -------- | -| Promise<ArrayBuffer> | 返回包含Blob数据的ArrayBuffer的Promise。 | +| Promise<ArrayBuffer> | Promise对象,返回包含Blob数据的ArrayBuffer。 | **示例:** ```ts @@ -2934,7 +2941,7 @@ pro.then(val => { slice(start?: number, end?: number, type?: string): Blob -创建并返回一个复制原blob对象中start到end位置数据的新blob实例对象。 +创建并返回一个复制原Blob对象中指定数据长度的Blob新对象。 **系统能力:** SystemCapability.Utils.Lang @@ -2962,14 +2969,14 @@ let blob3 = blob.slice(0, 2, "MIME"); text(): Promise<string> -返回一个Promise,该Promise中的值为UTF8编码类型的文本。 +使用UTF8进行解码并返回一个文本。使用Promise异步回调。 **系统能力:** SystemCapability.Utils.Lang **返回值:** | 类型 | 说明 | | -------- | -------- | -| Promise<string> | 包含以UTF8编码的文本的Promise。 | +| Promise<string> | Promise对象,返回包含以UTF8解码的文本。 | **示例:** ```ts diff --git a/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md b/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md index 75a644181d..20288e3df9 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md +++ b/zh-cn/application-dev/reference/apis/js-apis-lightweightmap.md @@ -275,7 +275,7 @@ let result = lightWeightMap.get("sparrow"); getIndexOfKey(key: K): number -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 +查找key元素第一次出现的下标值,如果没有找到该元素返回-1。 **系统能力:** SystemCapability.Utils.Lang @@ -289,7 +289,7 @@ getIndexOfKey(key: K): number | 类型 | 说明 | | -------- | -------- | -| number | 返回指定元素第一次出现时的下标值,查找失败返回-1。 | +| number | 返回key元素第一次出现时的下标值,查找失败返回-1。 | **错误码:** @@ -313,7 +313,7 @@ let result = lightWeightMap.getIndexOfKey("sparrow"); getIndexOfValue(value: V): number -查找指定元素第一次出现的下标值,如果没有找到该元素返回-1。 +查找value元素第一次出现的下标值,如果没有找到该元素返回-1。 **系统能力:** SystemCapability.Utils.Lang @@ -327,7 +327,7 @@ getIndexOfValue(value: V): number | 类型 | 说明 | | -------- | -------- | -| number | 返回指定元素第一次出现时的下标值,查找失败返回-1。 | +| number | 返回value元素第一次出现时的下标值,查找失败返回-1。 | **错误码:** diff --git a/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md b/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md index 2b7823b77e..795542ca64 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md +++ b/zh-cn/application-dev/reference/apis/js-apis-lightweightset.md @@ -1,4 +1,4 @@ -# @ohos.util.LightWeightSet (非线性容器LightWeightSet)@ohos.util.LightWeightSet (非线性容器LightWeightSet) +# @ohos.util.LightWeightSet (非线性容器LightWeightSet) > **说明:** > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md b/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md index 4add3e8a58..9d5589dc27 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md +++ b/zh-cn/application-dev/reference/apis/js-apis-linkedlist.md @@ -7,7 +7,7 @@ LinkedList底层通过双向链表实现,双向链表的每个节点都包含 LinkedList和[List](js-apis-list.md)相比,LinkedList是双向链表,可以快速地在头尾进行增删,而List是单向链表,无法双向操作。 -LinkedList和[ArrayList](js-apis-arraylist.md)相比,存取数据的效率不如ArrayList。 +LinkedList和[ArrayList](js-apis-arraylist.md)相比,插入数据效率LinkedList优于ArrayList,而查询效率ArrayList优于LinkedList。 **推荐使用场景:** 当需要频繁的插入删除时,推荐使用LinkedList高效操作。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-list.md b/zh-cn/application-dev/reference/apis/js-apis-list.md index 6437f970f4..4f9a669c94 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-list.md +++ b/zh-cn/application-dev/reference/apis/js-apis-list.md @@ -15,7 +15,7 @@ List和[LinkedList](js-apis-linkedlist.md)相比,LinkedList是双向链表, ## 导入模块 ```ts -import List from '@ohos.util.List'; +import List from '@ohos.util.List'; ``` @@ -546,8 +546,8 @@ list.add(2); list.add(4); list.add(5); list.add(4); -list.sort((a: number, b: number) => a - b); -list.sort((a: number, b: number) => b - a); +list.sort((a: number, b: number) => a - b); // 结果为升序排列 +list.sort((a: number, b: number) => b - a); // 结果为降序排列 ``` ### getSubList diff --git a/zh-cn/application-dev/reference/apis/js-apis-plainarray.md b/zh-cn/application-dev/reference/apis/js-apis-plainarray.md index fc77c00391..b99826fe94 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-plainarray.md +++ b/zh-cn/application-dev/reference/apis/js-apis-plainarray.md @@ -242,7 +242,7 @@ let result = plainArray.getIndexOfValue("squirrel"); getKeyAt(index: number): number -查找指定下标的元素键值对中key值。 +查找指定下标元素键值对中的key值。 **系统能力:** SystemCapability.Utils.Lang @@ -256,7 +256,7 @@ getKeyAt(index: number): number | 类型 | 说明 | | -------- | -------- | -| number | 返回该下标对应的元素键值对中key值,失败返回-1。 | +| number | 返回该下标元素键值对中的key值,失败返回-1。 | **错误码:** @@ -279,7 +279,7 @@ let result = plainArray.getKeyAt(1); getValueAt(index: number): T -查找指定下标元素键值对中Value值,否则返回undefined。 +查找指定下标元素键值对中的Value值,失败返回undefined。 **系统能力:** SystemCapability.Utils.Lang @@ -293,7 +293,7 @@ getValueAt(index: number): T | 类型 | 说明 | | -------- | -------- | - | T | 返回该下标对应的元素键值对中key值,失败返回undefined。 | + | T | 返回该下标元素键值对中的value值,失败返回undefined。 | **错误码:** diff --git a/zh-cn/application-dev/reference/apis/js-apis-url.md b/zh-cn/application-dev/reference/apis/js-apis-url.md index 2f68cab7da..48056ef989 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-url.md +++ b/zh-cn/application-dev/reference/apis/js-apis-url.md @@ -78,8 +78,8 @@ delete(name: string): void ```js let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsobject = new Url.URLParams(urlObject.search.slice(1)); -paramsobject.delete('fod'); +let paramsObject = new Url.URLParams(urlObject.search.slice(1)); +paramsObject.delete('fod'); ``` @@ -87,7 +87,7 @@ paramsobject.delete('fod'); getAll(name: string): string[] -获取指定名称的所有键值对。 +获取指定名称的所有键对应值的集合。 **系统能力:** SystemCapability.Utils.Lang @@ -101,7 +101,7 @@ getAll(name: string): string[] | 类型 | 说明 | | -------- | -------- | -| string[] | 返回指定名称的所有键值对。 | +| string[] | 返回指定名称的所有键对应值的集合。 | **示例:** -- GitLab