1e41f4b71Sopenharmony_ci# @ohos.buffer (Buffer) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciBuffer对象用于表示固定长度的字节序列,是专门存放二进制数据的缓存区。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**推荐使用场景:** 可用于处理大量二进制数据,图片处理、文件接收上传等。 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **说明:** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```ts 14e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## BufferEncoding 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci表示支持的编码格式类型。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| 类型 | 说明 | 26e41f4b71Sopenharmony_ci| ------- | -------------------- | 27e41f4b71Sopenharmony_ci| 'ascii' | 表示ascii格式。 | 28e41f4b71Sopenharmony_ci| 'utf8' | 表示utf8格式。 | 29e41f4b71Sopenharmony_ci| 'utf-8' | 表示utf8格式。 | 30e41f4b71Sopenharmony_ci| 'utf16le' | 表示utf16小端序格式。 | 31e41f4b71Sopenharmony_ci| 'ucs2' | utf16le的别名。 | 32e41f4b71Sopenharmony_ci| 'ucs-2' | utf16le的别名。 | 33e41f4b71Sopenharmony_ci| 'base64' | 表示base64格式。 | 34e41f4b71Sopenharmony_ci| 'base64url' | 表示base64url格式。 | 35e41f4b71Sopenharmony_ci| 'latin1' | iso-8859-1的别名, 向下兼容ascii格式。 | 36e41f4b71Sopenharmony_ci| 'binary' | 表示二进制格式。 | 37e41f4b71Sopenharmony_ci| 'hex' | 表示十六进制格式。 | 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## buffer.alloc 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_cialloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci创建一定字节长度的Buffer对象,并初始化。 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**参数:** 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 52e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 53e41f4b71Sopenharmony_ci| size | number | 是 | 指定的Buffer对象长度,单位:字节。 | 54e41f4b71Sopenharmony_ci| fill | string \| Buffer \| number | 否 | 填充至新缓存区的值,默认值: 0。 | 55e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码格式(当`fill`为string时,才有意义)。 默认值: 'utf8'。 | 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**返回值:** 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci| 类型 | 说明 | 60e41f4b71Sopenharmony_ci| -------- | -------- | 61e41f4b71Sopenharmony_ci| Buffer | 返回一个Buffer对象。 | 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci**错误码:** 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 68e41f4b71Sopenharmony_ci| -------- | -------- | 69e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**示例:** 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci```ts 74e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_cilet buf1 = buffer.alloc(5); 77e41f4b71Sopenharmony_cilet buf2 = buffer.alloc(5, 'a'); 78e41f4b71Sopenharmony_cilet buf3 = buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64'); 79e41f4b71Sopenharmony_ci``` 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci## buffer.allocUninitializedFromPool 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciallocUninitializedFromPool(size: number): Buffer 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci创建指定大小未被初始化的Buffer对象。内存从缓冲池分配。 86e41f4b71Sopenharmony_ci创建的Buffer的内容未知,需要使用[fill](#fill)函数来初始化Buffer对象。 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**参数:** 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 95e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 96e41f4b71Sopenharmony_ci| size | number | 是 | 指定的Buffer对象长度,单位:字节。 | 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**返回值:** 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci| 类型 | 说明 | 101e41f4b71Sopenharmony_ci| -------- | -------- | 102e41f4b71Sopenharmony_ci| Buffer | 未初始化的Buffer实例。 | 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci**错误码:** 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 109e41f4b71Sopenharmony_ci| -------- | -------- | 110e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**示例:** 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci```ts 115e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(10); 118e41f4b71Sopenharmony_cibuf.fill(0); 119e41f4b71Sopenharmony_ci``` 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci## buffer.allocUninitialized 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciallocUninitialized(size: number): Buffer 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci创建指定大小未被初始化的Buffer实例。内存不从缓冲池分配。 126e41f4b71Sopenharmony_ci创建的Buffer的内容未知,需要使用[fill](#fill)函数来初始化Buffer对象。 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**参数:** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 135e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 136e41f4b71Sopenharmony_ci| size | number | 是 |指定的Buffer对象长度,单位:字节。 | 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**返回值:** 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci| 类型 | 说明 | 141e41f4b71Sopenharmony_ci| -------- | -------- | 142e41f4b71Sopenharmony_ci| Buffer | 未初始化的Buffer实例。 | 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci**错误码:** 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 149e41f4b71Sopenharmony_ci| -------- | -------- | 150e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**示例:** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci```ts 155e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_cilet buf = buffer.allocUninitialized(10); 158e41f4b71Sopenharmony_cibuf.fill(0); 159e41f4b71Sopenharmony_ci``` 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci## buffer.byteLength 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_cibyteLength(string: string | Buffer | TypedArray | DataView | ArrayBuffer | SharedArrayBuffer, encoding?: BufferEncoding): number 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci根据不同的编码方法,返回指定字符串的字节数。 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**参数:** 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 174e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 175e41f4b71Sopenharmony_ci| string | string \| Buffer \| TypedArray \| DataView \| ArrayBuffer \| SharedArrayBuffer | 是 | 指定字符串。 | 176e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码格式。 默认值: 'utf8'。 | 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**返回值:** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| 类型 | 说明 | 181e41f4b71Sopenharmony_ci| -------- | -------- | 182e41f4b71Sopenharmony_ci| number | 返回指定字符串的字节数。 | 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**错误码:** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 189e41f4b71Sopenharmony_ci| -------- | -------- | 190e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**示例:** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci```ts 195e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_cilet str = '\u00bd + \u00bc = \u00be'; 198e41f4b71Sopenharmony_ciconsole.log(`${str}: ${str.length} characters, ${buffer.byteLength(str, 'utf-8')} bytes`); 199e41f4b71Sopenharmony_ci// 打印: ½ + ¼ = ¾: 9 characters, 12 bytes 200e41f4b71Sopenharmony_ci``` 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci## buffer.compare 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_cicompare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): -1 | 0 | 1 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci返回两个数组的比较结果,通常用于对Buffer对象数组进行排序。 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci**参数:** 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 215e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 216e41f4b71Sopenharmony_ci| buf1 | Buffer \| Uint8Array | 是 | 待比较数组。 | 217e41f4b71Sopenharmony_ci| buf2 | Buffer \| Uint8Array | 是 | 待比较数组。 | 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**返回值:** 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| 类型 | 说明 | 222e41f4b71Sopenharmony_ci| -------- | -------- | 223e41f4b71Sopenharmony_ci| -1 \| 0 \| 1 | 如果buf1与buf2相同,则返回0。<br/>如果排序时buf1位于buf2之后,则返回1。<br/>如果排序时buf1位于buf2之前,则返回-1。 | 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**错误码:** 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 230e41f4b71Sopenharmony_ci| -------- | -------- | 231e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**示例:** 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci```ts 236e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_cilet buf1 = buffer.from('1234'); 239e41f4b71Sopenharmony_cilet buf2 = buffer.from('0123'); 240e41f4b71Sopenharmony_cilet res = buf1.compare(buf2); 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciconsole.log(Number(res).toString()); // 打印 1 243e41f4b71Sopenharmony_ci``` 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci## buffer.concat 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ciconcat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci将数组中的内容复制指定字节长度到新的Buffer对象中并返回。 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**参数:** 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 258e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 259e41f4b71Sopenharmony_ci| list | Buffer[] \| Uint8Array[] | 是 | 实例数组。 | 260e41f4b71Sopenharmony_ci| totalLength | number | 否 | 需要复制的总字节长度,默认值为0。 | 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**返回值:** 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci| 类型 | 说明 | 265e41f4b71Sopenharmony_ci| -------- | -------- | 266e41f4b71Sopenharmony_ci| Buffer | 返回新的Buffer对象。 | 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci**错误码:** 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 273e41f4b71Sopenharmony_ci| -------- | -------- | 274e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 275e41f4b71Sopenharmony_ci| 10200001 | The value of "length" is out of range. It must be >= 0 and <= uint32 max. Received value is: [length] | 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**示例:** 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci```ts 280e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_cilet buf1 = buffer.from("1234"); 283e41f4b71Sopenharmony_cilet buf2 = buffer.from("abcd"); 284e41f4b71Sopenharmony_cilet buf = buffer.concat([buf1, buf2]); 285e41f4b71Sopenharmony_ciconsole.log(buf.toString('hex')); // 3132333461626364 286e41f4b71Sopenharmony_ci``` 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci## buffer.from 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_cifrom(array: number[]): Buffer; 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci根据指定数组创建新的Buffer对象。 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**参数:** 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 301e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 302e41f4b71Sopenharmony_ci| array | number[] | 是 | 指定数组。 | 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci**返回值:** 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci| 类型 | 说明 | 307e41f4b71Sopenharmony_ci| -------- | -------- | 308e41f4b71Sopenharmony_ci| Buffer | 新的Buffer对象。 | 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci**错误码:** 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 315e41f4b71Sopenharmony_ci| -------- | -------- | 316e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**示例:** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci```ts 321e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_cilet buf = buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]); 324e41f4b71Sopenharmony_ciconsole.log(buf.toString('hex')); // 627566666572 325e41f4b71Sopenharmony_ci``` 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci## buffer.from 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_cifrom(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci创建指定长度的与`arrayBuffer`共享内存的Buffer对象。 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci**参数:** 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 340e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 341e41f4b71Sopenharmony_ci| arrayBuffer | ArrayBuffer \| SharedArrayBuffer | 是 | 实例对象。 | 342e41f4b71Sopenharmony_ci| byteOffset | number | 否 | 字节偏移量,默认值: 0。 | 343e41f4b71Sopenharmony_ci| length | number | 否 | 字节长度, 默认值: (arrayBuffer.byteLength - byteOffset)。 | 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**返回值:** 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci| 类型 | 说明 | 348e41f4b71Sopenharmony_ci| -------- | -------- | 349e41f4b71Sopenharmony_ci| Buffer | 返回一个Buffer对象,与入参对象保持内存共享。 | 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci**错误码:** 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 356e41f4b71Sopenharmony_ci| -------- | -------- | 357e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 358e41f4b71Sopenharmony_ci| 10200001 | The value of "[byteOffset/length]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [byteOffset/length] | 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**示例:** 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci```ts 363e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_cilet ab = new ArrayBuffer(10); 366e41f4b71Sopenharmony_cilet buf = buffer.from(ab, 0, 2); 367e41f4b71Sopenharmony_ci``` 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci## buffer.from 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_cifrom(buffer: Buffer | Uint8Array): Buffer 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci当入参为Buffer对象时,创建并复制入参Buffer对象数据到新的Buffer对象并返回。</br> 374e41f4b71Sopenharmony_ci当入参为Uint8Array对象时,创建的Buffer对象持有Uint8Array对象的内存并返回,保持数据的内存关联。 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci**参数:** 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 383e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 384e41f4b71Sopenharmony_ci| buffer | Buffer \| Uint8Array | 是 | 对象数据。 | 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ci**返回值:** 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci| 类型 | 说明 | 389e41f4b71Sopenharmony_ci| -------- | -------- | 390e41f4b71Sopenharmony_ci| Buffer | 新的Buffer对象。 | 391e41f4b71Sopenharmony_ci 392e41f4b71Sopenharmony_ci**错误码:** 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 397e41f4b71Sopenharmony_ci| -------- | -------- | 398e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci**示例:** 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci```ts 403e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci// 以Buffer对象类型进行创建新的Buffer对象 406e41f4b71Sopenharmony_cilet buf1 = buffer.from('buffer'); 407e41f4b71Sopenharmony_cilet buf2 = buffer.from(buf1); 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci// 以Uint8Array对象类型进行创建Buffer对象,保持对象间内存共享 410e41f4b71Sopenharmony_cilet uint8Array = new Uint8Array(10); 411e41f4b71Sopenharmony_cilet buf3 = buffer.from(uint8Array); 412e41f4b71Sopenharmony_cibuf3.fill(1) 413e41f4b71Sopenharmony_ciconsole.info("uint8Array:", uint8Array) 414e41f4b71Sopenharmony_ci``` 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci## buffer.from 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_cifrom(object: Object, offsetOrEncoding: number | string, length: number): Buffer 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci根据指定的`object`类型数据,创建新的Buffer对象。 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**参数:** 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 429e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 430e41f4b71Sopenharmony_ci| object | Object | 是 | 支持Symbol.toPrimitive或valueOf()的对象。 | 431e41f4b71Sopenharmony_ci| offsetOrEncoding | number \| string | 是 | 字节偏移量或编码格式。 | 432e41f4b71Sopenharmony_ci| length | number | 是 | 字节长度(此入参仅在object的valueOf()返回值为ArrayBuffer时生效,取值范围:0 <= length <= ArrayBuffer.byteLength, 超出范围时报错: 10200001)。其他情况下可填任意number类型值,该参数不会对结果产生影响。 | 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**返回值:** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci| 类型 | 说明 | 437e41f4b71Sopenharmony_ci| -------- | -------- | 438e41f4b71Sopenharmony_ci| Buffer | 返回新的Buffer对象。 | 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci**错误码:** 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 445e41f4b71Sopenharmony_ci| -------- | -------- | 446e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**示例:** 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci```ts 451e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_cilet buf = buffer.from(new String('this is a test'), 'utf8', 14); 454e41f4b71Sopenharmony_ci``` 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci## buffer.from 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_cifrom(string: String, encoding?: BufferEncoding): Buffer 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci根据指定编码格式的字符串,创建新的Buffer对象。 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**参数:** 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 469e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 470e41f4b71Sopenharmony_ci| string | String | 是 | 字符串 | 471e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 编码格式。 默认值: 'utf8'。 | 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**返回值:** 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci| 类型 | 说明 | 476e41f4b71Sopenharmony_ci| -------- | -------- | 477e41f4b71Sopenharmony_ci| Buffer | 返回新的Buffer对象。 | 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**错误码:** 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 484e41f4b71Sopenharmony_ci| -------- | -------- | 485e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**示例:** 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci```ts 490e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_cilet buf1 = buffer.from('this is a test'); 493e41f4b71Sopenharmony_cilet buf2 = buffer.from('7468697320697320612074c3a97374', 'hex'); 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ciconsole.log(buf1.toString()); // 打印: this is a test 496e41f4b71Sopenharmony_ciconsole.log(buf2.toString()); // 打印: this is a tést 497e41f4b71Sopenharmony_ci``` 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci## buffer.isBuffer 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ciisBuffer(obj: Object): boolean 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci判断`obj`是否为Buffer。 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci**参数:** 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 513e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 514e41f4b71Sopenharmony_ci| obj | Object | 是 | 判断对象 | 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci**返回值:** 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci| 类型 | 说明 | 519e41f4b71Sopenharmony_ci| -------- | -------- | 520e41f4b71Sopenharmony_ci| boolean | 如果obj是Buffer,则返回true,否则返回false。 | 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci**示例:** 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci```ts 525e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_cilet result = buffer.isBuffer(buffer.alloc(10)); // true 528e41f4b71Sopenharmony_cilet result1 = buffer.isBuffer(buffer.from('foo')); // true 529e41f4b71Sopenharmony_cilet result2 = buffer.isBuffer('a string'); // false 530e41f4b71Sopenharmony_cilet result3 = buffer.isBuffer([]); // false 531e41f4b71Sopenharmony_cilet result4 = buffer.isBuffer(new Uint8Array(1024)); // false 532e41f4b71Sopenharmony_ci``` 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci## buffer.isEncoding 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ciisEncoding(encoding: string): boolean 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci判断`encoding`是否为支持的编码格式。 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci**参数:** 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 547e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 548e41f4b71Sopenharmony_ci| encoding | string | 是 | 编码格式。 | 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci**返回值:** 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci| 类型 | 说明 | 553e41f4b71Sopenharmony_ci| -------- | -------- | 554e41f4b71Sopenharmony_ci| boolean | 是支持的编码格式返回true,反之则返回false。 | 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci**示例:** 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci```ts 559e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ciconsole.log(buffer.isEncoding('utf-8').toString()); // 打印: true 562e41f4b71Sopenharmony_ciconsole.log(buffer.isEncoding('hex').toString()); // 打印: true 563e41f4b71Sopenharmony_ciconsole.log(buffer.isEncoding('utf/8').toString()); // 打印: false 564e41f4b71Sopenharmony_ciconsole.log(buffer.isEncoding('').toString()); // 打印: false 565e41f4b71Sopenharmony_ci``` 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci## buffer.transcode 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_citranscode(source: Buffer | Uint8Array, fromEnc: string, toEnc: string): Buffer 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci将给定的Buffer或Uint8Array对象从一种字符编码重新编码为另一种。 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ci**参数:** 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 580e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 581e41f4b71Sopenharmony_ci| source | Buffer \| Uint8Array | 是 | 实例对象。 | 582e41f4b71Sopenharmony_ci| fromEnc | string | 是 | 当前编码。 | 583e41f4b71Sopenharmony_ci| toEnc | string | 是 | 目标编码。 | 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci**返回值:** 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci| 类型 | 说明 | 588e41f4b71Sopenharmony_ci| -------- | -------- | 589e41f4b71Sopenharmony_ci| Buffer | 根据当前编码转换成目标编码,并返回一个新的buffer实例。 | 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci**错误码:** 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 596e41f4b71Sopenharmony_ci| -------- | -------- | 597e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci**示例:** 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci```ts 602e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_cilet newBuf = buffer.transcode(buffer.from('€'), 'utf-8', 'ascii'); 605e41f4b71Sopenharmony_ciconsole.log(newBuf.toString('ascii')); 606e41f4b71Sopenharmony_ci``` 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci## Buffer 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci### 属性 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 615e41f4b71Sopenharmony_ci 616e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 617e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 618e41f4b71Sopenharmony_ci| length | number | 是 | 否 | Buffer对象的字节长度。 | 619e41f4b71Sopenharmony_ci| buffer | ArrayBuffer | 是 | 否 | ArrayBuffer对象。 | 620e41f4b71Sopenharmony_ci| byteOffset | number | 是 | 否 | 当前Buffer所在内存池的偏移量。 | 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci**错误码:** 623e41f4b71Sopenharmony_ci 624e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 625e41f4b71Sopenharmony_ci 626e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 627e41f4b71Sopenharmony_ci| -------- | -------- | 628e41f4b71Sopenharmony_ci| 10200013 | ${propertyName} cannot be set for the buffer that has only a getter. | 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci**示例:** 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci```ts 633e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_cilet buf = buffer.from("1236"); 636e41f4b71Sopenharmony_ciconsole.log(JSON.stringify(buf.length)); 637e41f4b71Sopenharmony_cilet arrayBuffer = buf.buffer; 638e41f4b71Sopenharmony_ciconsole.log(JSON.stringify(new Uint8Array(arrayBuffer))); 639e41f4b71Sopenharmony_ciconsole.log(JSON.stringify(buf.byteOffset)); 640e41f4b71Sopenharmony_ci``` 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci### compare 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_cicompare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci当前Buffer对象与目标Buffer对象进行比较,并返回Buffer在排序中的顺序结果。 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**参数:** 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 655e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 656e41f4b71Sopenharmony_ci| target | Buffer \| Uint8Array | 是 | 要比较的实例对象。 | 657e41f4b71Sopenharmony_ci| targetStart | number | 否 | `target`实例中开始的偏移量。 默认值: 0。 | 658e41f4b71Sopenharmony_ci| targetEnd | number | 否 | `target`实例中结束的偏移量(不包含结束位置)。 默认值: 目标对象的字节长度。 | 659e41f4b71Sopenharmony_ci| sourceStart | number | 否 | `this`实例中开始的偏移量。 默认值: 0。 | 660e41f4b71Sopenharmony_ci| sourceEnd | number | 否 | `this`实例中结束的偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**返回值:** 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci| 类型 | 说明 | 665e41f4b71Sopenharmony_ci| -------- | -------- | 666e41f4b71Sopenharmony_ci| number | 返回比较结果。-1:当前排列在目标前,0:当前与目标相同,1:当前排列在目标后。 | 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci**错误码:** 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 673e41f4b71Sopenharmony_ci| -------- | -------- | 674e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 675e41f4b71Sopenharmony_ci| 10200001 | The value of "[targetStart/targetEnd/sourceStart/sourceEnd]" is out of range. | 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci**示例:** 678e41f4b71Sopenharmony_ci 679e41f4b71Sopenharmony_ci```ts 680e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_cilet buf1 = buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]); 683e41f4b71Sopenharmony_cilet buf2 = buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]); 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ciconsole.log(buf1.compare(buf2, 5, 9, 0, 4).toString()); // 打印: 0 686e41f4b71Sopenharmony_ciconsole.log(buf1.compare(buf2, 0, 6, 4).toString()); // 打印: -1 687e41f4b71Sopenharmony_ciconsole.log(buf1.compare(buf2, 5, 6, 5).toString()); // 打印: 1 688e41f4b71Sopenharmony_ci``` 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci### copy 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_cicopy(target: Buffer| Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ci将`this`实例中指定位置的数据复制到`target`的指定位置上,并返回复制的字节总长度。 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci**参数:** 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 703e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 704e41f4b71Sopenharmony_ci| target | Buffer \| Uint8Array | 是 | 要复制到的Buffer或Uint8Array实例。 | 705e41f4b71Sopenharmony_ci| targetStart | number | 否 | `target`实例中开始写入的偏移量。 默认值: 0。 | 706e41f4b71Sopenharmony_ci| sourceStart | number | 否 | `this`实例中开始复制的偏移量。 默认值: 0。 | 707e41f4b71Sopenharmony_ci| sourceEnd | number | 否 | `this`实例中结束复制的偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci**返回值:** 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci| 类型 | 说明 | 712e41f4b71Sopenharmony_ci| -------- | -------- | 713e41f4b71Sopenharmony_ci| number | 复制的字节总长度。 | 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci**错误码:** 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 720e41f4b71Sopenharmony_ci| -------- | -------- | 721e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 722e41f4b71Sopenharmony_ci| 10200001 | The value of "[targetStart/sourceStart/sourceEnd]" is out of range. | 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci**示例:** 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci```ts 727e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(26); 730e41f4b71Sopenharmony_cilet buf2 = buffer.allocUninitializedFromPool(26).fill('!'); 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_cifor (let i = 0; i < 26; i++) { 733e41f4b71Sopenharmony_ci buf1.writeInt8(i + 97, i); 734e41f4b71Sopenharmony_ci} 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_cibuf1.copy(buf2, 8, 16, 20); 737e41f4b71Sopenharmony_ciconsole.log(buf2.toString('ascii', 0, 25)); 738e41f4b71Sopenharmony_ci// 打印: !!!!!!!!qrst!!!!!!!!!!!!! 739e41f4b71Sopenharmony_ci``` 740e41f4b71Sopenharmony_ci 741e41f4b71Sopenharmony_ci### entries 742e41f4b71Sopenharmony_ci 743e41f4b71Sopenharmony_cientries(): IterableIterator<[number, number]> 744e41f4b71Sopenharmony_ci 745e41f4b71Sopenharmony_ci返回一个包含key和value的迭代器。 746e41f4b71Sopenharmony_ci 747e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci**返回值:** 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_ci| 类型 | 说明 | 754e41f4b71Sopenharmony_ci| -------- | -------- | 755e41f4b71Sopenharmony_ci| IterableIterator<[number, number]> | 包含key和value的迭代器,同时两者皆为number类型。 | 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**示例:** 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci```ts 760e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_cilet buf = buffer.from('buffer'); 763e41f4b71Sopenharmony_cilet pair = buf.entries(); 764e41f4b71Sopenharmony_cilet next: IteratorResult<Object[]> = pair.next(); 765e41f4b71Sopenharmony_ciwhile (!next.done) { 766e41f4b71Sopenharmony_ci console.info("buffer: " + next.value); 767e41f4b71Sopenharmony_ci next = pair.next(); 768e41f4b71Sopenharmony_ci} 769e41f4b71Sopenharmony_ci``` 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci### equals 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ciequals(otherBuffer: Uint8Array | Buffer): boolean 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci比较`this`实例和otherBuffer实例是否相等。 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_ci**参数:** 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 784e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 785e41f4b71Sopenharmony_ci| otherBuffer | Uint8Array \| Buffer | 是 | 比较的目标对象。 | 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci**返回值:** 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci| 类型 | 说明 | 790e41f4b71Sopenharmony_ci| -------- | -------- | 791e41f4b71Sopenharmony_ci| boolean | 相等则返回true,否则返回false。 | 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci**错误码:** 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 798e41f4b71Sopenharmony_ci| -------- | -------- | 799e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_ci**示例:** 802e41f4b71Sopenharmony_ci 803e41f4b71Sopenharmony_ci```ts 804e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_cilet buf1 = buffer.from('ABC'); 807e41f4b71Sopenharmony_cilet buf2 = buffer.from('414243', 'hex'); 808e41f4b71Sopenharmony_cilet buf3 = buffer.from('ABCD'); 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ciconsole.log(buf1.equals(buf2).toString()); // 打印: true 811e41f4b71Sopenharmony_ciconsole.log(buf1.equals(buf3).toString()); // 打印: false 812e41f4b71Sopenharmony_ci``` 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ci### fill 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_cifill(value: string | Buffer | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): Buffer 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci用`value`填充当前对象指定位置的数据,默认为循环填充,并返回填充后的Buffer对象。 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci**参数:** 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 827e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 828e41f4b71Sopenharmony_ci| value | string \| Buffer \| Uint8Array \| number | 是 | 用于填充的值。 | 829e41f4b71Sopenharmony_ci| offset | number | 否 | 起始偏移量。 默认值: 0。 | 830e41f4b71Sopenharmony_ci| end | number | 否 | 结束偏移量(不包含结束位置)。 默认值: 当前对象的字节长度。 | 831e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式(`value`为string才有意义)。 默认值: 'utf8'。 | 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ci**返回值:** 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci| 类型 | 说明 | 836e41f4b71Sopenharmony_ci| -------- | -------- | 837e41f4b71Sopenharmony_ci| Buffer | 返回一个填充后的Buffer对象。 | 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci**错误码:** 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 844e41f4b71Sopenharmony_ci| -------- | -------- | 845e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 846e41f4b71Sopenharmony_ci| 10200001 | The value of "[offset/end]" is out of range. | 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci**示例:** 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci```ts 851e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_cilet b = buffer.allocUninitializedFromPool(50).fill('h'); 854e41f4b71Sopenharmony_ciconsole.log(b.toString()); 855e41f4b71Sopenharmony_ci``` 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci### includes 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ciincludes(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): boolean 861e41f4b71Sopenharmony_ci 862e41f4b71Sopenharmony_ci检查Buffer对象是否包含`value`值。 863e41f4b71Sopenharmony_ci 864e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ci**参数:** 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 871e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 872e41f4b71Sopenharmony_ci| value | string \| number \| Buffer \| Uint8Array | 是 | 要搜索的内容。 | 873e41f4b71Sopenharmony_ci| byteOffset | number | 否 | 字节偏移量。 如果为负数,则从末尾开始计算偏移量。 默认值: 0。 | 874e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式。 默认值: 'utf8'。 | 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_ci**返回值:** 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci| 类型 | 说明 | 879e41f4b71Sopenharmony_ci| -------- | -------- | 880e41f4b71Sopenharmony_ci| boolean | 存在为true,否则为false。 | 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci**错误码:** 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 887e41f4b71Sopenharmony_ci| -------- | -------- | 888e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ci**示例:** 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci```ts 893e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 894e41f4b71Sopenharmony_ci 895e41f4b71Sopenharmony_cilet buf = buffer.from('this is a buffer'); 896e41f4b71Sopenharmony_ciconsole.log(buf.includes('this').toString()); // 打印: true 897e41f4b71Sopenharmony_ciconsole.log(buf.includes('be').toString()); // 打印: false 898e41f4b71Sopenharmony_ci``` 899e41f4b71Sopenharmony_ci 900e41f4b71Sopenharmony_ci### indexOf 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ciindexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci查找当前对象中第一次出现`value`的索引,如果不包含`value`,则为-1。 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 909e41f4b71Sopenharmony_ci 910e41f4b71Sopenharmony_ci**参数:** 911e41f4b71Sopenharmony_ci 912e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 913e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 914e41f4b71Sopenharmony_ci| value | string \| number \| Buffer \| Uint8Array | 是 | 要查找的内容。 | 915e41f4b71Sopenharmony_ci| byteOffset | number | 否 | 字节偏移量。 如果为负数,则从末尾开始计算偏移量。 默认值: 0。 | 916e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式。 默认值: 'utf8'。 | 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_ci**返回值:** 919e41f4b71Sopenharmony_ci 920e41f4b71Sopenharmony_ci| 类型 | 说明 | 921e41f4b71Sopenharmony_ci| -------- | -------- | 922e41f4b71Sopenharmony_ci| number | 第一次出现位置。 | 923e41f4b71Sopenharmony_ci 924e41f4b71Sopenharmony_ci**错误码:** 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 929e41f4b71Sopenharmony_ci| -------- | -------- | 930e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci**示例:** 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci```ts 935e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 936e41f4b71Sopenharmony_ci 937e41f4b71Sopenharmony_cilet buf = buffer.from('this is a buffer'); 938e41f4b71Sopenharmony_ciconsole.log(buf.indexOf('this').toString()); // 打印: 0 939e41f4b71Sopenharmony_ciconsole.log(buf.indexOf('is').toString()); // 打印: 2 940e41f4b71Sopenharmony_ci``` 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci### keys 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_cikeys(): IterableIterator<number> 945e41f4b71Sopenharmony_ci 946e41f4b71Sopenharmony_ci返回一个包含key值的迭代器。 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 951e41f4b71Sopenharmony_ci 952e41f4b71Sopenharmony_ci**返回值:** 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ci| 类型 | 说明 | 955e41f4b71Sopenharmony_ci| -------- | -------- | 956e41f4b71Sopenharmony_ci| IterableIterator<number> | 返回一个包含key值的迭代器。 | 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci**示例:** 959e41f4b71Sopenharmony_ci 960e41f4b71Sopenharmony_ci```ts 961e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_cilet buf = buffer.from('buffer'); 964e41f4b71Sopenharmony_cilet numbers = Array.from(buf.keys()); 965e41f4b71Sopenharmony_cifor (const key of numbers) { 966e41f4b71Sopenharmony_ci console.log(key.toString()); 967e41f4b71Sopenharmony_ci} 968e41f4b71Sopenharmony_ci``` 969e41f4b71Sopenharmony_ci 970e41f4b71Sopenharmony_ci### lastIndexOf 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_cilastIndexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ci返回`this`实例中最后一次出现`value`的索引,如果对象不包含,则为-1。 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci**参数:** 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 983e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 984e41f4b71Sopenharmony_ci| value | string \| number \| Buffer \| Uint8Array | 是 | 要搜索的内容。 | 985e41f4b71Sopenharmony_ci| byteOffset | number | 否 | 字节偏移量。 如果为负数,则从末尾开始计算偏移量。 默认值: Buffer.length。 | 986e41f4b71Sopenharmony_ci| encoding | [BufferEncoding](#bufferencoding) | 否 | 字符编码格式。 默认值: 'utf8'。 | 987e41f4b71Sopenharmony_ci 988e41f4b71Sopenharmony_ci**返回值:** 989e41f4b71Sopenharmony_ci 990e41f4b71Sopenharmony_ci| 类型 | 说明 | 991e41f4b71Sopenharmony_ci| -------- | -------- | 992e41f4b71Sopenharmony_ci| number | 最后一次出现`value`值的索引。 | 993e41f4b71Sopenharmony_ci 994e41f4b71Sopenharmony_ci**错误码:** 995e41f4b71Sopenharmony_ci 996e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 997e41f4b71Sopenharmony_ci 998e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 999e41f4b71Sopenharmony_ci| -------- | -------- | 1000e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ci**示例:** 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci```ts 1005e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_cilet buf = buffer.from('this buffer is a buffer'); 1008e41f4b71Sopenharmony_ciconsole.log(buf.lastIndexOf('this').toString()); // 打印: 0 1009e41f4b71Sopenharmony_ciconsole.log(buf.lastIndexOf('buffer').toString()); // 打印: 17 1010e41f4b71Sopenharmony_ci``` 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci### readBigInt64BE 1014e41f4b71Sopenharmony_ci 1015e41f4b71Sopenharmony_cireadBigInt64BE(offset?: number): bigint 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的大端序64位整数。 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1020e41f4b71Sopenharmony_ci 1021e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1022e41f4b71Sopenharmony_ci 1023e41f4b71Sopenharmony_ci**参数:** 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1026e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1027e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。默认值: 0。取值范围:0 <= offset <= Buffer.length - 8 | 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci**返回值:** 1030e41f4b71Sopenharmony_ci 1031e41f4b71Sopenharmony_ci| 类型 | 说明 | 1032e41f4b71Sopenharmony_ci| -------- | -------- | 1033e41f4b71Sopenharmony_ci| bigint | 读取出的内容。 | 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ci**错误码:** 1036e41f4b71Sopenharmony_ci 1037e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1040e41f4b71Sopenharmony_ci| -------- | -------- | 1041e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1042e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ci**示例:** 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci```ts 1047e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_cilet buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 1050e41f4b71Sopenharmony_ci 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]); 1051e41f4b71Sopenharmony_ciconsole.log(buf.readBigInt64BE(0).toString()); 1052e41f4b71Sopenharmony_ci 1053e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1054e41f4b71Sopenharmony_cilet result = buf1.writeBigInt64BE(BigInt(0x0102030405060708), 0); 1055e41f4b71Sopenharmony_ci``` 1056e41f4b71Sopenharmony_ci 1057e41f4b71Sopenharmony_ci### readBigInt64LE 1058e41f4b71Sopenharmony_ci 1059e41f4b71Sopenharmony_cireadBigInt64LE(offset?: number): bigint 1060e41f4b71Sopenharmony_ci 1061e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的小端序64位整数。 1062e41f4b71Sopenharmony_ci 1063e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci**参数:** 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1070e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1071e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 8,默认值: 0。 | 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci**返回值:** 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci| 类型 | 说明 | 1076e41f4b71Sopenharmony_ci| -------- | -------- | 1077e41f4b71Sopenharmony_ci| bigint | 读取出的内容。 | 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci**错误码:** 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1084e41f4b71Sopenharmony_ci| -------- | -------- | 1085e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1086e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1087e41f4b71Sopenharmony_ci 1088e41f4b71Sopenharmony_ci**示例:** 1089e41f4b71Sopenharmony_ci 1090e41f4b71Sopenharmony_ci```ts 1091e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_cilet buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 1094e41f4b71Sopenharmony_ci 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]); 1095e41f4b71Sopenharmony_ciconsole.log(buf.readBigInt64LE(0).toString()); 1096e41f4b71Sopenharmony_ci 1097e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1098e41f4b71Sopenharmony_cilet result = buf1.writeBigInt64BE(BigInt(0x0102030405060708), 0); 1099e41f4b71Sopenharmony_ci``` 1100e41f4b71Sopenharmony_ci 1101e41f4b71Sopenharmony_ci### readBigUInt64BE 1102e41f4b71Sopenharmony_ci 1103e41f4b71Sopenharmony_cireadBigUInt64BE(offset?: number): bigint 1104e41f4b71Sopenharmony_ci 1105e41f4b71Sopenharmony_ci从指定的`offset`处读取无符号的大端序64位整数。 1106e41f4b71Sopenharmony_ci 1107e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1108e41f4b71Sopenharmony_ci 1109e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1110e41f4b71Sopenharmony_ci 1111e41f4b71Sopenharmony_ci**参数:** 1112e41f4b71Sopenharmony_ci 1113e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1114e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1115e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 8,默认值: 0。 | 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci**返回值:** 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci| 类型 | 说明 | 1120e41f4b71Sopenharmony_ci| -------- | -------- | 1121e41f4b71Sopenharmony_ci| bigint | 读取出的内容。 | 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci**错误码:** 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1128e41f4b71Sopenharmony_ci| -------- | -------- | 1129e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1130e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1131e41f4b71Sopenharmony_ci 1132e41f4b71Sopenharmony_ci**示例:** 1133e41f4b71Sopenharmony_ci 1134e41f4b71Sopenharmony_ci```ts 1135e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_cilet buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 1138e41f4b71Sopenharmony_ci 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]); 1139e41f4b71Sopenharmony_ciconsole.log(buf.readBigUInt64BE(0).toString()); 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1142e41f4b71Sopenharmony_cilet result = buf1.writeBigUInt64BE(BigInt(0xdecafafecacefade), 0); 1143e41f4b71Sopenharmony_ci``` 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci### readBigUInt64LE 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_cireadBigUInt64LE(offset?: number): bigint 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ci从指定的`offset`处读取无符号的小端序64位整数。 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci**参数:** 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1158e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1159e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 8,默认值: 0。 | 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_ci**返回值:** 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci| 类型 | 说明 | 1164e41f4b71Sopenharmony_ci| -------- | -------- | 1165e41f4b71Sopenharmony_ci| bigint | 读取出的内容。 | 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci**错误码:** 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1170e41f4b71Sopenharmony_ci 1171e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1172e41f4b71Sopenharmony_ci| -------- | -------- | 1173e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1174e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci**示例:** 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci```ts 1179e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1180e41f4b71Sopenharmony_ci 1181e41f4b71Sopenharmony_cilet buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 1182e41f4b71Sopenharmony_ci 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]); 1183e41f4b71Sopenharmony_ciconsole.log(buf.readBigUInt64LE(0).toString()); 1184e41f4b71Sopenharmony_ci 1185e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1186e41f4b71Sopenharmony_cilet result = buf1.writeBigUInt64BE(BigInt(0xdecafafecacefade), 0); 1187e41f4b71Sopenharmony_ci``` 1188e41f4b71Sopenharmony_ci 1189e41f4b71Sopenharmony_ci### readDoubleBE 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_cireadDoubleBE(offset?: number): number 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ci从指定`offset`处读取64位大端序双精度值。 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1198e41f4b71Sopenharmony_ci 1199e41f4b71Sopenharmony_ci**参数:** 1200e41f4b71Sopenharmony_ci 1201e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1202e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1203e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 8,默认值: 0。 | 1204e41f4b71Sopenharmony_ci 1205e41f4b71Sopenharmony_ci**返回值:** 1206e41f4b71Sopenharmony_ci 1207e41f4b71Sopenharmony_ci| 类型 | 说明 | 1208e41f4b71Sopenharmony_ci| -------- | -------- | 1209e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1210e41f4b71Sopenharmony_ci 1211e41f4b71Sopenharmony_ci**错误码:** 1212e41f4b71Sopenharmony_ci 1213e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1216e41f4b71Sopenharmony_ci| -------- | -------- | 1217e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1218e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci**示例:** 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci```ts 1223e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1224e41f4b71Sopenharmony_ci 1225e41f4b71Sopenharmony_cilet buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); 1226e41f4b71Sopenharmony_ciconsole.log(buf.readDoubleBE(0).toString()); 1227e41f4b71Sopenharmony_ci 1228e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1229e41f4b71Sopenharmony_cilet result = buf1.writeDoubleBE(123.456, 0); 1230e41f4b71Sopenharmony_ci``` 1231e41f4b71Sopenharmony_ci 1232e41f4b71Sopenharmony_ci### readDoubleLE 1233e41f4b71Sopenharmony_ci 1234e41f4b71Sopenharmony_cireadDoubleLE(offset?: number): number 1235e41f4b71Sopenharmony_ci 1236e41f4b71Sopenharmony_ci从指定`offset`处读取64位小端序双精度值。 1237e41f4b71Sopenharmony_ci 1238e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_ci**参数:** 1243e41f4b71Sopenharmony_ci 1244e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1245e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1246e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 8,默认值: 0。 | 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci**返回值:** 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci| 类型 | 说明 | 1251e41f4b71Sopenharmony_ci| -------- | -------- | 1252e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1253e41f4b71Sopenharmony_ci 1254e41f4b71Sopenharmony_ci**错误码:** 1255e41f4b71Sopenharmony_ci 1256e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1257e41f4b71Sopenharmony_ci 1258e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1259e41f4b71Sopenharmony_ci| -------- | -------- | 1260e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1261e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset]. | 1262e41f4b71Sopenharmony_ci 1263e41f4b71Sopenharmony_ci**示例:** 1264e41f4b71Sopenharmony_ci 1265e41f4b71Sopenharmony_ci```ts 1266e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1267e41f4b71Sopenharmony_ci 1268e41f4b71Sopenharmony_cilet buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); 1269e41f4b71Sopenharmony_ciconsole.log(buf.readDoubleLE(0).toString()); 1270e41f4b71Sopenharmony_ci 1271e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(8); 1272e41f4b71Sopenharmony_cilet result = buf1.writeDoubleLE(123.456, 0); 1273e41f4b71Sopenharmony_ci``` 1274e41f4b71Sopenharmony_ci 1275e41f4b71Sopenharmony_ci### readFloatBE 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_cireadFloatBE(offset?: number): number 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_ci从指定`offset`处读取32位大端序浮点数。 1280e41f4b71Sopenharmony_ci 1281e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci**参数:** 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1288e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1289e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci**返回值:** 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci| 类型 | 说明 | 1294e41f4b71Sopenharmony_ci| -------- | -------- | 1295e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1296e41f4b71Sopenharmony_ci 1297e41f4b71Sopenharmony_ci**错误码:** 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1302e41f4b71Sopenharmony_ci| -------- | -------- | 1303e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1304e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1305e41f4b71Sopenharmony_ci 1306e41f4b71Sopenharmony_ci**示例:** 1307e41f4b71Sopenharmony_ci 1308e41f4b71Sopenharmony_ci```ts 1309e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_cilet buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); 1312e41f4b71Sopenharmony_ciconsole.log(buf.readFloatBE(0).toString()); 1313e41f4b71Sopenharmony_ci 1314e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1315e41f4b71Sopenharmony_cilet result = buf1.writeFloatBE(0xcabcbcbc, 0); 1316e41f4b71Sopenharmony_ci``` 1317e41f4b71Sopenharmony_ci 1318e41f4b71Sopenharmony_ci### readFloatLE 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_cireadFloatLE(offset?: number): number 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci从指定`offset`处读取32位小端序浮点数。 1323e41f4b71Sopenharmony_ci 1324e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci**参数:** 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1331e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1332e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1333e41f4b71Sopenharmony_ci 1334e41f4b71Sopenharmony_ci**返回值:** 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci| 类型 | 说明 | 1337e41f4b71Sopenharmony_ci| -------- | -------- | 1338e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1339e41f4b71Sopenharmony_ci 1340e41f4b71Sopenharmony_ci**错误码:** 1341e41f4b71Sopenharmony_ci 1342e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1343e41f4b71Sopenharmony_ci 1344e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1345e41f4b71Sopenharmony_ci| -------- | -------- | 1346e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1347e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci**示例:** 1350e41f4b71Sopenharmony_ci 1351e41f4b71Sopenharmony_ci```ts 1352e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1353e41f4b71Sopenharmony_ci 1354e41f4b71Sopenharmony_cilet buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); 1355e41f4b71Sopenharmony_ciconsole.log(buf.readFloatLE(0).toString()); 1356e41f4b71Sopenharmony_ci 1357e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1358e41f4b71Sopenharmony_cilet result = buf1.writeFloatLE(0xcabcbcbc, 0); 1359e41f4b71Sopenharmony_ci``` 1360e41f4b71Sopenharmony_ci 1361e41f4b71Sopenharmony_ci### readInt8 1362e41f4b71Sopenharmony_ci 1363e41f4b71Sopenharmony_cireadInt8(offset?: number): number 1364e41f4b71Sopenharmony_ci 1365e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的8位整数。 1366e41f4b71Sopenharmony_ci 1367e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1368e41f4b71Sopenharmony_ci 1369e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ci**参数:** 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1374e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1375e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 1,默认值: 0。 | 1376e41f4b71Sopenharmony_ci 1377e41f4b71Sopenharmony_ci**返回值:** 1378e41f4b71Sopenharmony_ci 1379e41f4b71Sopenharmony_ci| 类型 | 说明 | 1380e41f4b71Sopenharmony_ci| -------- | -------- | 1381e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci**错误码:** 1384e41f4b71Sopenharmony_ci 1385e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1386e41f4b71Sopenharmony_ci 1387e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1388e41f4b71Sopenharmony_ci| -------- | -------- | 1389e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1390e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 1. Received value is: [offset]. | 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci**示例:** 1393e41f4b71Sopenharmony_ci 1394e41f4b71Sopenharmony_ci```ts 1395e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_cilet buf = buffer.from([-1, 5]); 1398e41f4b71Sopenharmony_ciconsole.log(buf.readInt8(0).toString()); // 打印: 0 1399e41f4b71Sopenharmony_ciconsole.log(buf.readInt8(1).toString()); // 打印: 5 1400e41f4b71Sopenharmony_ci 1401e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(2); 1402e41f4b71Sopenharmony_cilet result = buf1.writeInt8(0x12); 1403e41f4b71Sopenharmony_ci``` 1404e41f4b71Sopenharmony_ci 1405e41f4b71Sopenharmony_ci### readInt16BE 1406e41f4b71Sopenharmony_ci 1407e41f4b71Sopenharmony_cireadInt16BE(offset?: number): number 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的大端序16位整数。 1410e41f4b71Sopenharmony_ci 1411e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1412e41f4b71Sopenharmony_ci 1413e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1414e41f4b71Sopenharmony_ci 1415e41f4b71Sopenharmony_ci**参数:** 1416e41f4b71Sopenharmony_ci 1417e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1418e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1419e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 2,默认值: 0。 | 1420e41f4b71Sopenharmony_ci 1421e41f4b71Sopenharmony_ci**返回值:** 1422e41f4b71Sopenharmony_ci 1423e41f4b71Sopenharmony_ci| 类型 | 说明 | 1424e41f4b71Sopenharmony_ci| -------- | -------- | 1425e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1426e41f4b71Sopenharmony_ci 1427e41f4b71Sopenharmony_ci**错误码:** 1428e41f4b71Sopenharmony_ci 1429e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1430e41f4b71Sopenharmony_ci 1431e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1432e41f4b71Sopenharmony_ci| -------- | -------- | 1433e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1434e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset]. | 1435e41f4b71Sopenharmony_ci 1436e41f4b71Sopenharmony_ci**示例:** 1437e41f4b71Sopenharmony_ci 1438e41f4b71Sopenharmony_ci```ts 1439e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1440e41f4b71Sopenharmony_ci 1441e41f4b71Sopenharmony_cilet buf = buffer.from([0, 5]); 1442e41f4b71Sopenharmony_ciconsole.log(buf.readInt16BE(0).toString()); // 打印: 5 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_cilet buf1 = buffer.alloc(2); 1445e41f4b71Sopenharmony_cilet result = buf1.writeInt16BE(0x1234, 0); 1446e41f4b71Sopenharmony_ci``` 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci### readInt16LE 1449e41f4b71Sopenharmony_ci 1450e41f4b71Sopenharmony_cireadInt16LE(offset?: number): number 1451e41f4b71Sopenharmony_ci 1452e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的小端序16位整数。 1453e41f4b71Sopenharmony_ci 1454e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1455e41f4b71Sopenharmony_ci 1456e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ci**参数:** 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1461e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1462e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 2,默认值: 0。 | 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci**返回值:** 1465e41f4b71Sopenharmony_ci 1466e41f4b71Sopenharmony_ci| 类型 | 说明 | 1467e41f4b71Sopenharmony_ci| -------- | -------- | 1468e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1469e41f4b71Sopenharmony_ci 1470e41f4b71Sopenharmony_ci**错误码:** 1471e41f4b71Sopenharmony_ci 1472e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1473e41f4b71Sopenharmony_ci 1474e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1475e41f4b71Sopenharmony_ci| -------- | -------- | 1476e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1477e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset]. | 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci**示例:** 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci```ts 1482e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1483e41f4b71Sopenharmony_ci 1484e41f4b71Sopenharmony_cilet buf = buffer.from([0, 5]); 1485e41f4b71Sopenharmony_ciconsole.log(buf.readInt16LE(0).toString()); // 打印: 1280 1486e41f4b71Sopenharmony_ci 1487e41f4b71Sopenharmony_cilet buf1 = buffer.alloc(2); 1488e41f4b71Sopenharmony_cilet result = buf1.writeInt16BE(0x1234, 0); 1489e41f4b71Sopenharmony_ci``` 1490e41f4b71Sopenharmony_ci 1491e41f4b71Sopenharmony_ci### readInt32BE 1492e41f4b71Sopenharmony_ci 1493e41f4b71Sopenharmony_cireadInt32BE(offset?: number): number 1494e41f4b71Sopenharmony_ci 1495e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的大端序32位整数。 1496e41f4b71Sopenharmony_ci 1497e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1498e41f4b71Sopenharmony_ci 1499e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ci**参数:** 1502e41f4b71Sopenharmony_ci 1503e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1504e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1505e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci**返回值:** 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ci| 类型 | 说明 | 1510e41f4b71Sopenharmony_ci| -------- | -------- | 1511e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1512e41f4b71Sopenharmony_ci 1513e41f4b71Sopenharmony_ci**错误码:** 1514e41f4b71Sopenharmony_ci 1515e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1516e41f4b71Sopenharmony_ci 1517e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1518e41f4b71Sopenharmony_ci| -------- | -------- | 1519e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1520e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_ci**示例:** 1523e41f4b71Sopenharmony_ci 1524e41f4b71Sopenharmony_ci```ts 1525e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_cilet buf = buffer.from([0, 0, 0, 5]); 1528e41f4b71Sopenharmony_ciconsole.log(buf.readInt32BE(0).toString()); // 打印: 5 1529e41f4b71Sopenharmony_ci 1530e41f4b71Sopenharmony_cilet buf1 = buffer.alloc(4); 1531e41f4b71Sopenharmony_cilet result = buf1.writeInt32BE(0x12345678, 0); 1532e41f4b71Sopenharmony_ci``` 1533e41f4b71Sopenharmony_ci 1534e41f4b71Sopenharmony_ci### readInt32LE 1535e41f4b71Sopenharmony_ci 1536e41f4b71Sopenharmony_cireadInt32LE(offset?: number): number 1537e41f4b71Sopenharmony_ci 1538e41f4b71Sopenharmony_ci从指定的`offset`处读取有符号的小端序32位整数。 1539e41f4b71Sopenharmony_ci 1540e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1541e41f4b71Sopenharmony_ci 1542e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1543e41f4b71Sopenharmony_ci 1544e41f4b71Sopenharmony_ci**参数:** 1545e41f4b71Sopenharmony_ci 1546e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1547e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1548e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1549e41f4b71Sopenharmony_ci 1550e41f4b71Sopenharmony_ci**返回值:** 1551e41f4b71Sopenharmony_ci 1552e41f4b71Sopenharmony_ci| 类型 | 说明 | 1553e41f4b71Sopenharmony_ci| -------- | -------- | 1554e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1555e41f4b71Sopenharmony_ci 1556e41f4b71Sopenharmony_ci**错误码:** 1557e41f4b71Sopenharmony_ci 1558e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1559e41f4b71Sopenharmony_ci 1560e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1561e41f4b71Sopenharmony_ci| -------- | -------- | 1562e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. | 1563e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1564e41f4b71Sopenharmony_ci 1565e41f4b71Sopenharmony_ci**示例:** 1566e41f4b71Sopenharmony_ci 1567e41f4b71Sopenharmony_ci```ts 1568e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_cilet buf = buffer.from([0, 0, 0, 5]); 1571e41f4b71Sopenharmony_ciconsole.log(buf.readInt32LE(0).toString()); // 打印: 83886080 1572e41f4b71Sopenharmony_ci 1573e41f4b71Sopenharmony_cilet buf1 = buffer.alloc(4); 1574e41f4b71Sopenharmony_cilet result = buf1.writeInt32BE(0x12345678, 0); 1575e41f4b71Sopenharmony_ci``` 1576e41f4b71Sopenharmony_ci 1577e41f4b71Sopenharmony_ci### readIntBE 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_cireadIntBE(offset: number, byteLength: number): number 1580e41f4b71Sopenharmony_ci 1581e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取byteLength个字节,并将结果解释为支持最高48位精度的大端序、二进制补码有符号值。 1582e41f4b71Sopenharmony_ci 1583e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1584e41f4b71Sopenharmony_ci 1585e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci**参数:** 1588e41f4b71Sopenharmony_ci 1589e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1590e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1591e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。取值范围:0 <= offset <= Buffer.length - byteLength,默认值: 0。 | 1592e41f4b71Sopenharmony_ci| byteLength | number | 是 | 读取的字节数。取值范围:1 <= byteLength <= 6。 | 1593e41f4b71Sopenharmony_ci 1594e41f4b71Sopenharmony_ci 1595e41f4b71Sopenharmony_ci**返回值:** 1596e41f4b71Sopenharmony_ci 1597e41f4b71Sopenharmony_ci| 类型 | 说明 | 1598e41f4b71Sopenharmony_ci| -------- | -------- | 1599e41f4b71Sopenharmony_ci| number | 读取的内容。当offset为小数时,返回undefined。 | 1600e41f4b71Sopenharmony_ci 1601e41f4b71Sopenharmony_ci**错误码:** 1602e41f4b71Sopenharmony_ci 1603e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1604e41f4b71Sopenharmony_ci 1605e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1606e41f4b71Sopenharmony_ci| -------- | -------- | 1607e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1608e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_ci**示例:** 1611e41f4b71Sopenharmony_ci 1612e41f4b71Sopenharmony_ci```ts 1613e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_cilet buf = buffer.from("ab"); 1616e41f4b71Sopenharmony_cilet num = buf.readIntBE(0, 1); 1617e41f4b71Sopenharmony_ciconsole.log(num.toString()); // 97 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(6); 1620e41f4b71Sopenharmony_cilet result = buf1.writeIntBE(0x123456789011, 0, 6); 1621e41f4b71Sopenharmony_ci``` 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ci 1624e41f4b71Sopenharmony_ci### readIntLE 1625e41f4b71Sopenharmony_ci 1626e41f4b71Sopenharmony_cireadIntLE(offset: number, byteLength: number): number 1627e41f4b71Sopenharmony_ci 1628e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取`byteLength`个字节,并将结果解释为支持最高48位精度的小端序、二进制补码有符号值。 1629e41f4b71Sopenharmony_ci 1630e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1631e41f4b71Sopenharmony_ci 1632e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1633e41f4b71Sopenharmony_ci 1634e41f4b71Sopenharmony_ci**参数:** 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1637e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1638e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。取值范围:0 <= offset <= Buffer.length - byteLength,默认值: 0。 | 1639e41f4b71Sopenharmony_ci| byteLength | number | 是 | 读取的字节数。取值范围:1 <= byteLength <= 6。| 1640e41f4b71Sopenharmony_ci 1641e41f4b71Sopenharmony_ci 1642e41f4b71Sopenharmony_ci**返回值:** 1643e41f4b71Sopenharmony_ci 1644e41f4b71Sopenharmony_ci| 类型 | 说明 | 1645e41f4b71Sopenharmony_ci| -------- | -------- | 1646e41f4b71Sopenharmony_ci| number | 读取出的内容。当offset为小数时,返回undefined。 | 1647e41f4b71Sopenharmony_ci 1648e41f4b71Sopenharmony_ci**错误码:** 1649e41f4b71Sopenharmony_ci 1650e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1651e41f4b71Sopenharmony_ci 1652e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1653e41f4b71Sopenharmony_ci| -------- | -------- | 1654e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1655e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 1656e41f4b71Sopenharmony_ci 1657e41f4b71Sopenharmony_ci**示例:** 1658e41f4b71Sopenharmony_ci 1659e41f4b71Sopenharmony_ci```ts 1660e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1661e41f4b71Sopenharmony_ci 1662e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); 1663e41f4b71Sopenharmony_ciconsole.log(buf.readIntLE(0, 6).toString(16)); 1664e41f4b71Sopenharmony_ci 1665e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(6); 1666e41f4b71Sopenharmony_cilet result = buf1.writeIntLE(0x123456789011, 0, 6); 1667e41f4b71Sopenharmony_ci``` 1668e41f4b71Sopenharmony_ci 1669e41f4b71Sopenharmony_ci### readUInt8 1670e41f4b71Sopenharmony_ci 1671e41f4b71Sopenharmony_cireadUInt8(offset?: number): number 1672e41f4b71Sopenharmony_ci 1673e41f4b71Sopenharmony_ci从`offset`处读取8位无符号整型数。 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ci**参数:** 1680e41f4b71Sopenharmony_ci 1681e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1682e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1683e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 1,默认值: 0。 | 1684e41f4b71Sopenharmony_ci 1685e41f4b71Sopenharmony_ci 1686e41f4b71Sopenharmony_ci**返回值:** 1687e41f4b71Sopenharmony_ci 1688e41f4b71Sopenharmony_ci| 类型 | 说明 | 1689e41f4b71Sopenharmony_ci| -------- | -------- | 1690e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1691e41f4b71Sopenharmony_ci 1692e41f4b71Sopenharmony_ci**错误码:** 1693e41f4b71Sopenharmony_ci 1694e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1695e41f4b71Sopenharmony_ci 1696e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1697e41f4b71Sopenharmony_ci| -------- | -------- | 1698e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 1699e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 1. Received value is: [offset]. | 1700e41f4b71Sopenharmony_ci 1701e41f4b71Sopenharmony_ci**示例:** 1702e41f4b71Sopenharmony_ci 1703e41f4b71Sopenharmony_ci```ts 1704e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1705e41f4b71Sopenharmony_ci 1706e41f4b71Sopenharmony_cilet buf = buffer.from([1, -2]); 1707e41f4b71Sopenharmony_ciconsole.log(buf.readUInt8(0).toString()); 1708e41f4b71Sopenharmony_ciconsole.log(buf.readUInt8(1).toString()); 1709e41f4b71Sopenharmony_ci 1710e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1711e41f4b71Sopenharmony_cilet result = buf1.writeUInt8(0x42); 1712e41f4b71Sopenharmony_ci``` 1713e41f4b71Sopenharmony_ci 1714e41f4b71Sopenharmony_ci### readUInt16BE 1715e41f4b71Sopenharmony_ci 1716e41f4b71Sopenharmony_cireadUInt16BE(offset?: number): number 1717e41f4b71Sopenharmony_ci 1718e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取无符号的大端序16位整数。 1719e41f4b71Sopenharmony_ci 1720e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1721e41f4b71Sopenharmony_ci 1722e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1723e41f4b71Sopenharmony_ci 1724e41f4b71Sopenharmony_ci**参数:** 1725e41f4b71Sopenharmony_ci 1726e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1727e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1728e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 2,默认值: 0。 | 1729e41f4b71Sopenharmony_ci 1730e41f4b71Sopenharmony_ci 1731e41f4b71Sopenharmony_ci**返回值:** 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_ci| 类型 | 说明 | 1734e41f4b71Sopenharmony_ci| -------- | -------- | 1735e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1736e41f4b71Sopenharmony_ci 1737e41f4b71Sopenharmony_ci**错误码:** 1738e41f4b71Sopenharmony_ci 1739e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1740e41f4b71Sopenharmony_ci 1741e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1742e41f4b71Sopenharmony_ci| -------- | -------- | 1743e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 1744e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset]. | 1745e41f4b71Sopenharmony_ci 1746e41f4b71Sopenharmony_ci**示例:** 1747e41f4b71Sopenharmony_ci 1748e41f4b71Sopenharmony_ci```ts 1749e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1750e41f4b71Sopenharmony_ci 1751e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56]); 1752e41f4b71Sopenharmony_ciconsole.log(buf.readUInt16BE(0).toString(16)); 1753e41f4b71Sopenharmony_ciconsole.log(buf.readUInt16BE(1).toString(16)); 1754e41f4b71Sopenharmony_ci 1755e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1756e41f4b71Sopenharmony_cilet result = buf1.writeUInt16BE(0x1234, 0); 1757e41f4b71Sopenharmony_ci``` 1758e41f4b71Sopenharmony_ci 1759e41f4b71Sopenharmony_ci### readUInt16LE 1760e41f4b71Sopenharmony_ci 1761e41f4b71Sopenharmony_cireadUInt16LE(offset?: number): number 1762e41f4b71Sopenharmony_ci 1763e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取无符号的小端序16位整数。 1764e41f4b71Sopenharmony_ci 1765e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1766e41f4b71Sopenharmony_ci 1767e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1768e41f4b71Sopenharmony_ci 1769e41f4b71Sopenharmony_ci**参数:** 1770e41f4b71Sopenharmony_ci 1771e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1772e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1773e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 2,默认值: 0。 | 1774e41f4b71Sopenharmony_ci 1775e41f4b71Sopenharmony_ci 1776e41f4b71Sopenharmony_ci**返回值:** 1777e41f4b71Sopenharmony_ci 1778e41f4b71Sopenharmony_ci| 类型 | 说明 | 1779e41f4b71Sopenharmony_ci| -------- | -------- | 1780e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1781e41f4b71Sopenharmony_ci 1782e41f4b71Sopenharmony_ci**错误码:** 1783e41f4b71Sopenharmony_ci 1784e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1785e41f4b71Sopenharmony_ci 1786e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1787e41f4b71Sopenharmony_ci| -------- | -------- | 1788e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 1789e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset]. | 1790e41f4b71Sopenharmony_ci 1791e41f4b71Sopenharmony_ci**示例:** 1792e41f4b71Sopenharmony_ci 1793e41f4b71Sopenharmony_ci```ts 1794e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1795e41f4b71Sopenharmony_ci 1796e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56]); 1797e41f4b71Sopenharmony_ciconsole.log(buf.readUInt16LE(0).toString(16)); 1798e41f4b71Sopenharmony_ciconsole.log(buf.readUInt16LE(1).toString(16)); 1799e41f4b71Sopenharmony_ci 1800e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1801e41f4b71Sopenharmony_cilet result = buf1.writeUInt16LE(0x1234, 0); 1802e41f4b71Sopenharmony_ci``` 1803e41f4b71Sopenharmony_ci 1804e41f4b71Sopenharmony_ci### readUInt32BE 1805e41f4b71Sopenharmony_ci 1806e41f4b71Sopenharmony_cireadUInt32BE(offset?: number): number 1807e41f4b71Sopenharmony_ci 1808e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取无符号的大端序32位整数。 1809e41f4b71Sopenharmony_ci 1810e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1811e41f4b71Sopenharmony_ci 1812e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1813e41f4b71Sopenharmony_ci 1814e41f4b71Sopenharmony_ci**参数:** 1815e41f4b71Sopenharmony_ci 1816e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1817e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1818e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1819e41f4b71Sopenharmony_ci 1820e41f4b71Sopenharmony_ci 1821e41f4b71Sopenharmony_ci**返回值:** 1822e41f4b71Sopenharmony_ci 1823e41f4b71Sopenharmony_ci| 类型 | 说明 | 1824e41f4b71Sopenharmony_ci| -------- | -------- | 1825e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1826e41f4b71Sopenharmony_ci 1827e41f4b71Sopenharmony_ci**错误码:** 1828e41f4b71Sopenharmony_ci 1829e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1830e41f4b71Sopenharmony_ci 1831e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1832e41f4b71Sopenharmony_ci| -------- | -------- | 1833e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 1834e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1835e41f4b71Sopenharmony_ci 1836e41f4b71Sopenharmony_ci**示例:** 1837e41f4b71Sopenharmony_ci 1838e41f4b71Sopenharmony_ci```ts 1839e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1840e41f4b71Sopenharmony_ci 1841e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56, 0x78]); 1842e41f4b71Sopenharmony_ciconsole.log(buf.readUInt32BE(0).toString(16)); 1843e41f4b71Sopenharmony_ci 1844e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1845e41f4b71Sopenharmony_cilet result = buf1.writeUInt32BE(0x12345678, 0); 1846e41f4b71Sopenharmony_ci``` 1847e41f4b71Sopenharmony_ci 1848e41f4b71Sopenharmony_ci### readUInt32LE 1849e41f4b71Sopenharmony_ci 1850e41f4b71Sopenharmony_cireadUInt32LE(offset?: number): number 1851e41f4b71Sopenharmony_ci 1852e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取无符号的小端序32位整数。 1853e41f4b71Sopenharmony_ci 1854e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1855e41f4b71Sopenharmony_ci 1856e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1857e41f4b71Sopenharmony_ci 1858e41f4b71Sopenharmony_ci**参数:** 1859e41f4b71Sopenharmony_ci 1860e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1861e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1862e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。取值范围:0 <= offset <= Buffer.length - 4,默认值: 0。 | 1863e41f4b71Sopenharmony_ci 1864e41f4b71Sopenharmony_ci 1865e41f4b71Sopenharmony_ci**返回值:** 1866e41f4b71Sopenharmony_ci 1867e41f4b71Sopenharmony_ci| 类型 | 说明 | 1868e41f4b71Sopenharmony_ci| -------- | -------- | 1869e41f4b71Sopenharmony_ci| number | 读取出的内容。 | 1870e41f4b71Sopenharmony_ci 1871e41f4b71Sopenharmony_ci**错误码:** 1872e41f4b71Sopenharmony_ci 1873e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1874e41f4b71Sopenharmony_ci 1875e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1876e41f4b71Sopenharmony_ci| -------- | -------- | 1877e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 1878e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset]. | 1879e41f4b71Sopenharmony_ci 1880e41f4b71Sopenharmony_ci**示例:** 1881e41f4b71Sopenharmony_ci 1882e41f4b71Sopenharmony_ci```ts 1883e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1884e41f4b71Sopenharmony_ci 1885e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56, 0x78]); 1886e41f4b71Sopenharmony_ciconsole.log(buf.readUInt32LE(0).toString(16)); 1887e41f4b71Sopenharmony_ci 1888e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1889e41f4b71Sopenharmony_cilet result = buf1.writeUInt32LE(0x12345678, 0); 1890e41f4b71Sopenharmony_ci``` 1891e41f4b71Sopenharmony_ci 1892e41f4b71Sopenharmony_ci### readUIntBE 1893e41f4b71Sopenharmony_ci 1894e41f4b71Sopenharmony_cireadUIntBE(offset: number, byteLength: number): number 1895e41f4b71Sopenharmony_ci 1896e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取`byteLength`个字节,并将结果解释为支持最高48位精度的无符号大端序整数。 1897e41f4b71Sopenharmony_ci 1898e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1899e41f4b71Sopenharmony_ci 1900e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1901e41f4b71Sopenharmony_ci 1902e41f4b71Sopenharmony_ci**参数:** 1903e41f4b71Sopenharmony_ci 1904e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1905e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1906e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。取值范围:0 <= offset <= Buffer.length - byteLength,默认值: 0。 | 1907e41f4b71Sopenharmony_ci| byteLength | number | 是 | 要读取的字节数。读取的字节数。取值范围:1 <= byteLength <= 6。 | 1908e41f4b71Sopenharmony_ci 1909e41f4b71Sopenharmony_ci 1910e41f4b71Sopenharmony_ci**返回值:** 1911e41f4b71Sopenharmony_ci 1912e41f4b71Sopenharmony_ci| 类型 | 说明 | 1913e41f4b71Sopenharmony_ci| -------- | -------- | 1914e41f4b71Sopenharmony_ci| number | 读取出的内容。当offset为小数时,返回undefined。 | 1915e41f4b71Sopenharmony_ci 1916e41f4b71Sopenharmony_ci**错误码:** 1917e41f4b71Sopenharmony_ci 1918e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1919e41f4b71Sopenharmony_ci 1920e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1921e41f4b71Sopenharmony_ci| -------- | -------- | 1922e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1923e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 1924e41f4b71Sopenharmony_ci 1925e41f4b71Sopenharmony_ci**示例:** 1926e41f4b71Sopenharmony_ci 1927e41f4b71Sopenharmony_ci```ts 1928e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1929e41f4b71Sopenharmony_ci 1930e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); 1931e41f4b71Sopenharmony_ciconsole.log(buf.readUIntBE(0, 6).toString(16)); 1932e41f4b71Sopenharmony_ci 1933e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1934e41f4b71Sopenharmony_cilet result = buf1.writeUIntBE(0x13141516, 0, 4); 1935e41f4b71Sopenharmony_ci``` 1936e41f4b71Sopenharmony_ci 1937e41f4b71Sopenharmony_ci### readUIntLE 1938e41f4b71Sopenharmony_ci 1939e41f4b71Sopenharmony_cireadUIntLE(offset: number, byteLength: number): number 1940e41f4b71Sopenharmony_ci 1941e41f4b71Sopenharmony_ci从指定的`offset`处的buf读取`byteLength`个字节,并将结果解释为支持最高48位精度的无符号小端序整数。 1942e41f4b71Sopenharmony_ci 1943e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1944e41f4b71Sopenharmony_ci 1945e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1946e41f4b71Sopenharmony_ci 1947e41f4b71Sopenharmony_ci**参数:** 1948e41f4b71Sopenharmony_ci 1949e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1950e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1951e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。取值范围:0 <= offset <= Buffer.length - byteLength,默认值: 0。 | 1952e41f4b71Sopenharmony_ci| byteLength | number | 是 | 读取的字节数。取值范围:1 <= byteLength <= 6。 | 1953e41f4b71Sopenharmony_ci 1954e41f4b71Sopenharmony_ci 1955e41f4b71Sopenharmony_ci**返回值:** 1956e41f4b71Sopenharmony_ci 1957e41f4b71Sopenharmony_ci| 类型 | 说明 | 1958e41f4b71Sopenharmony_ci| -------- | -------- | 1959e41f4b71Sopenharmony_ci| number | 读取出的内容。当offset为小数时,返回undefined。 | 1960e41f4b71Sopenharmony_ci 1961e41f4b71Sopenharmony_ci**错误码:** 1962e41f4b71Sopenharmony_ci 1963e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 1964e41f4b71Sopenharmony_ci 1965e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1966e41f4b71Sopenharmony_ci| -------- | -------- | 1967e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1968e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 1969e41f4b71Sopenharmony_ci 1970e41f4b71Sopenharmony_ci**示例:** 1971e41f4b71Sopenharmony_ci 1972e41f4b71Sopenharmony_ci```ts 1973e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 1974e41f4b71Sopenharmony_ci 1975e41f4b71Sopenharmony_cilet buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]); 1976e41f4b71Sopenharmony_ciconsole.log(buf.readUIntLE(0, 6).toString(16)); 1977e41f4b71Sopenharmony_ci 1978e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(4); 1979e41f4b71Sopenharmony_cilet result = buf1.writeUIntLE(0x13141516, 0, 4); 1980e41f4b71Sopenharmony_ci``` 1981e41f4b71Sopenharmony_ci 1982e41f4b71Sopenharmony_ci### subarray 1983e41f4b71Sopenharmony_ci 1984e41f4b71Sopenharmony_cisubarray(start?: number, end?: number): Buffer 1985e41f4b71Sopenharmony_ci 1986e41f4b71Sopenharmony_ci截取当前对象指定位置的数据并返回。 1987e41f4b71Sopenharmony_ci 1988e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 1989e41f4b71Sopenharmony_ci 1990e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 1991e41f4b71Sopenharmony_ci 1992e41f4b71Sopenharmony_ci**参数:** 1993e41f4b71Sopenharmony_ci 1994e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1995e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 1996e41f4b71Sopenharmony_ci| start | number | 否 | 截取开始位置。 默认值: 0。 | 1997e41f4b71Sopenharmony_ci| end | number | 否 | 截取结束位置(不包含结束位置)。 默认值: 当前对象的字节长度。 | 1998e41f4b71Sopenharmony_ci 1999e41f4b71Sopenharmony_ci**返回值:** 2000e41f4b71Sopenharmony_ci 2001e41f4b71Sopenharmony_ci| 类型 | 说明 | 2002e41f4b71Sopenharmony_ci| -------- | -------- | 2003e41f4b71Sopenharmony_ci| Buffer | 返回新的Buffer对象。当 start < 0 或 end < 0 时返回一个空Buffer。 | 2004e41f4b71Sopenharmony_ci 2005e41f4b71Sopenharmony_ci**示例:** 2006e41f4b71Sopenharmony_ci 2007e41f4b71Sopenharmony_ci```ts 2008e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2009e41f4b71Sopenharmony_ci 2010e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(26); 2011e41f4b71Sopenharmony_ci 2012e41f4b71Sopenharmony_cifor (let i = 0; i < 26; i++) { 2013e41f4b71Sopenharmony_ci buf1.writeInt8(i + 97, i); 2014e41f4b71Sopenharmony_ci} 2015e41f4b71Sopenharmony_ciconst buf2 = buf1.subarray(0, 3); 2016e41f4b71Sopenharmony_ciconsole.log(buf2.toString('ascii', 0, buf2.length)); 2017e41f4b71Sopenharmony_ci// 打印: abc 2018e41f4b71Sopenharmony_ci``` 2019e41f4b71Sopenharmony_ci 2020e41f4b71Sopenharmony_ci### swap16 2021e41f4b71Sopenharmony_ci 2022e41f4b71Sopenharmony_ciswap16(): Buffer 2023e41f4b71Sopenharmony_ci 2024e41f4b71Sopenharmony_ci将当前对象解释为无符号的16位整数数组,并交换字节顺序。 2025e41f4b71Sopenharmony_ci 2026e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2027e41f4b71Sopenharmony_ci 2028e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2029e41f4b71Sopenharmony_ci 2030e41f4b71Sopenharmony_ci 2031e41f4b71Sopenharmony_ci**返回值:** 2032e41f4b71Sopenharmony_ci 2033e41f4b71Sopenharmony_ci| 类型 | 说明 | 2034e41f4b71Sopenharmony_ci| -------- | -------- | 2035e41f4b71Sopenharmony_ci| Buffer | 交换之后的Buffer实例。 | 2036e41f4b71Sopenharmony_ci 2037e41f4b71Sopenharmony_ci**错误码:** 2038e41f4b71Sopenharmony_ci 2039e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 2040e41f4b71Sopenharmony_ci 2041e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2042e41f4b71Sopenharmony_ci| -------- | -------- | 2043e41f4b71Sopenharmony_ci| 10200009 | The buffer size must be a multiple of 16-bits. | 2044e41f4b71Sopenharmony_ci 2045e41f4b71Sopenharmony_ci**示例:** 2046e41f4b71Sopenharmony_ci 2047e41f4b71Sopenharmony_ci```ts 2048e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2049e41f4b71Sopenharmony_ci 2050e41f4b71Sopenharmony_cilet buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); 2051e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0102030405060708 2052e41f4b71Sopenharmony_ci 2053e41f4b71Sopenharmony_cibuf1.swap16(); 2054e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0201040306050807 2055e41f4b71Sopenharmony_ci``` 2056e41f4b71Sopenharmony_ci 2057e41f4b71Sopenharmony_ci### swap32 2058e41f4b71Sopenharmony_ci 2059e41f4b71Sopenharmony_ciswap32(): Buffer 2060e41f4b71Sopenharmony_ci 2061e41f4b71Sopenharmony_ci将当前对象解释为无符号的32位整数数组,并交换字节顺序。 2062e41f4b71Sopenharmony_ci 2063e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2064e41f4b71Sopenharmony_ci 2065e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2066e41f4b71Sopenharmony_ci 2067e41f4b71Sopenharmony_ci 2068e41f4b71Sopenharmony_ci**返回值:** 2069e41f4b71Sopenharmony_ci 2070e41f4b71Sopenharmony_ci| 类型 | 说明 | 2071e41f4b71Sopenharmony_ci| -------- | -------- | 2072e41f4b71Sopenharmony_ci| Buffer | 交换之后的Buffer对象。 | 2073e41f4b71Sopenharmony_ci 2074e41f4b71Sopenharmony_ci**错误码:** 2075e41f4b71Sopenharmony_ci 2076e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 2077e41f4b71Sopenharmony_ci 2078e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2079e41f4b71Sopenharmony_ci| -------- | -------- | 2080e41f4b71Sopenharmony_ci| 10200009 | The buffer size must be a multiple of 32-bits. | 2081e41f4b71Sopenharmony_ci 2082e41f4b71Sopenharmony_ci**示例:** 2083e41f4b71Sopenharmony_ci 2084e41f4b71Sopenharmony_ci```ts 2085e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2086e41f4b71Sopenharmony_ci 2087e41f4b71Sopenharmony_cilet buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); 2088e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0102030405060708 2089e41f4b71Sopenharmony_ci 2090e41f4b71Sopenharmony_cibuf1.swap32(); 2091e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0403020108070605 2092e41f4b71Sopenharmony_ci``` 2093e41f4b71Sopenharmony_ci 2094e41f4b71Sopenharmony_ci### swap64 2095e41f4b71Sopenharmony_ci 2096e41f4b71Sopenharmony_ciswap64(): Buffer 2097e41f4b71Sopenharmony_ci 2098e41f4b71Sopenharmony_ci将当前对象解释为无符号的64位整数数组,并交换字节顺序。 2099e41f4b71Sopenharmony_ci 2100e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2101e41f4b71Sopenharmony_ci 2102e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2103e41f4b71Sopenharmony_ci 2104e41f4b71Sopenharmony_ci 2105e41f4b71Sopenharmony_ci**返回值:** 2106e41f4b71Sopenharmony_ci 2107e41f4b71Sopenharmony_ci| 类型 | 说明 | 2108e41f4b71Sopenharmony_ci| -------- | -------- | 2109e41f4b71Sopenharmony_ci| Buffer | 交换之后的Buffer对象。 | 2110e41f4b71Sopenharmony_ci 2111e41f4b71Sopenharmony_ci**错误码:** 2112e41f4b71Sopenharmony_ci 2113e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。 2114e41f4b71Sopenharmony_ci 2115e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2116e41f4b71Sopenharmony_ci| -------- | -------- | 2117e41f4b71Sopenharmony_ci| 10200009 | The buffer size must be a multiple of 64-bits. | 2118e41f4b71Sopenharmony_ci 2119e41f4b71Sopenharmony_ci**示例:** 2120e41f4b71Sopenharmony_ci 2121e41f4b71Sopenharmony_ci```ts 2122e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2123e41f4b71Sopenharmony_ci 2124e41f4b71Sopenharmony_cilet buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]); 2125e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0102030405060708 2126e41f4b71Sopenharmony_cibuf1.swap64(); 2127e41f4b71Sopenharmony_ciconsole.log(buf1.toString('hex')); // 打印: 0807060504030201 2128e41f4b71Sopenharmony_ci``` 2129e41f4b71Sopenharmony_ci 2130e41f4b71Sopenharmony_ci### toJSON 2131e41f4b71Sopenharmony_ci 2132e41f4b71Sopenharmony_citoJSON(): Object 2133e41f4b71Sopenharmony_ci 2134e41f4b71Sopenharmony_ci将Buffer转为JSON并返回。 2135e41f4b71Sopenharmony_ci 2136e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2137e41f4b71Sopenharmony_ci 2138e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2139e41f4b71Sopenharmony_ci 2140e41f4b71Sopenharmony_ci 2141e41f4b71Sopenharmony_ci**返回值:** 2142e41f4b71Sopenharmony_ci 2143e41f4b71Sopenharmony_ci| 类型 | 说明 | 2144e41f4b71Sopenharmony_ci| -------- | -------- | 2145e41f4b71Sopenharmony_ci| Object | JSON对象。 | 2146e41f4b71Sopenharmony_ci 2147e41f4b71Sopenharmony_ci**示例:** 2148e41f4b71Sopenharmony_ci 2149e41f4b71Sopenharmony_ci```ts 2150e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2151e41f4b71Sopenharmony_ci 2152e41f4b71Sopenharmony_cilet buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]); 2153e41f4b71Sopenharmony_cilet obj = buf1.toJSON(); 2154e41f4b71Sopenharmony_ciconsole.log(JSON.stringify(obj)); 2155e41f4b71Sopenharmony_ci// 打印: {"type":"Buffer","data":[1,2,3,4,5]} 2156e41f4b71Sopenharmony_ci``` 2157e41f4b71Sopenharmony_ci 2158e41f4b71Sopenharmony_ci### toString 2159e41f4b71Sopenharmony_ci 2160e41f4b71Sopenharmony_citoString(encoding?: string, start?: number, end?: number): string 2161e41f4b71Sopenharmony_ci 2162e41f4b71Sopenharmony_ci将当前对象中指定位置数据转成指定编码格式字符串并返回。 2163e41f4b71Sopenharmony_ci 2164e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2165e41f4b71Sopenharmony_ci 2166e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2167e41f4b71Sopenharmony_ci 2168e41f4b71Sopenharmony_ci**参数:** 2169e41f4b71Sopenharmony_ci 2170e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2171e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2172e41f4b71Sopenharmony_ci| encoding | string | 否 | 字符编码格式。 默认值: 'utf8'。 | 2173e41f4b71Sopenharmony_ci| start | number | 否 | 开始位置。 默认值: 0。 | 2174e41f4b71Sopenharmony_ci| end | number | 否 | 结束位置。 默认值: Buffer.length。 | 2175e41f4b71Sopenharmony_ci 2176e41f4b71Sopenharmony_ci**返回值:** 2177e41f4b71Sopenharmony_ci 2178e41f4b71Sopenharmony_ci| 类型 | 说明 | 2179e41f4b71Sopenharmony_ci| -------- | -------- | 2180e41f4b71Sopenharmony_ci| string | 字符串。 当start >= Buffer.length 或 start > end 时返回空字符串。 | 2181e41f4b71Sopenharmony_ci 2182e41f4b71Sopenharmony_ci**错误码:** 2183e41f4b71Sopenharmony_ci 2184e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2185e41f4b71Sopenharmony_ci 2186e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2187e41f4b71Sopenharmony_ci| -------- | -------- | 2188e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 2189e41f4b71Sopenharmony_ci 2190e41f4b71Sopenharmony_ci**示例:** 2191e41f4b71Sopenharmony_ci 2192e41f4b71Sopenharmony_ci```ts 2193e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2194e41f4b71Sopenharmony_ci 2195e41f4b71Sopenharmony_cilet buf1 = buffer.allocUninitializedFromPool(26); 2196e41f4b71Sopenharmony_cifor (let i = 0; i < 26; i++) { 2197e41f4b71Sopenharmony_ci buf1.writeInt8(i + 97, i); 2198e41f4b71Sopenharmony_ci} 2199e41f4b71Sopenharmony_ciconsole.log(buf1.toString('utf-8')); 2200e41f4b71Sopenharmony_ci// 打印: abcdefghijklmnopqrstuvwxyz 2201e41f4b71Sopenharmony_ci``` 2202e41f4b71Sopenharmony_ci 2203e41f4b71Sopenharmony_ci### values 2204e41f4b71Sopenharmony_ci 2205e41f4b71Sopenharmony_civalues(): IterableIterator<number> 2206e41f4b71Sopenharmony_ci 2207e41f4b71Sopenharmony_ci返回一个包含value的迭代器。 2208e41f4b71Sopenharmony_ci 2209e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2210e41f4b71Sopenharmony_ci 2211e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2212e41f4b71Sopenharmony_ci 2213e41f4b71Sopenharmony_ci**返回值:** 2214e41f4b71Sopenharmony_ci 2215e41f4b71Sopenharmony_ci| 类型 | 说明 | 2216e41f4b71Sopenharmony_ci| -------- | -------- | 2217e41f4b71Sopenharmony_ci| IterableIterator<number> | 迭代器。 | 2218e41f4b71Sopenharmony_ci 2219e41f4b71Sopenharmony_ci**示例:** 2220e41f4b71Sopenharmony_ci 2221e41f4b71Sopenharmony_ci```ts 2222e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2223e41f4b71Sopenharmony_ci 2224e41f4b71Sopenharmony_cilet buf1 = buffer.from('buffer'); 2225e41f4b71Sopenharmony_cilet pair = buf1.values() 2226e41f4b71Sopenharmony_cilet next:IteratorResult<number> = pair.next() 2227e41f4b71Sopenharmony_ciwhile (!next.done) { 2228e41f4b71Sopenharmony_ci console.log(next.value.toString()); 2229e41f4b71Sopenharmony_ci next = pair.next(); 2230e41f4b71Sopenharmony_ci} 2231e41f4b71Sopenharmony_ci``` 2232e41f4b71Sopenharmony_ci 2233e41f4b71Sopenharmony_ci### write 2234e41f4b71Sopenharmony_ci 2235e41f4b71Sopenharmony_ciwrite(str: string, offset?: number, length?: number, encoding?: string): number 2236e41f4b71Sopenharmony_ci 2237e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入指定编码的字符串str,写入的字节长度为length。 2238e41f4b71Sopenharmony_ci 2239e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2240e41f4b71Sopenharmony_ci 2241e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2242e41f4b71Sopenharmony_ci 2243e41f4b71Sopenharmony_ci**参数:** 2244e41f4b71Sopenharmony_ci 2245e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2246e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2247e41f4b71Sopenharmony_ci| str | string | 是 | 要写入Buffer的字符串。 | 2248e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。 | 2249e41f4b71Sopenharmony_ci| length | number | 否 | 最大字节长度。 默认值: (Buffer.length - offset)。| 2250e41f4b71Sopenharmony_ci| encoding | string | 否 | 字符编码。 默认值: 'utf8'。 | 2251e41f4b71Sopenharmony_ci 2252e41f4b71Sopenharmony_ci 2253e41f4b71Sopenharmony_ci**返回值:** 2254e41f4b71Sopenharmony_ci 2255e41f4b71Sopenharmony_ci| 类型 | 说明 | 2256e41f4b71Sopenharmony_ci| -------- | -------- | 2257e41f4b71Sopenharmony_ci| number | 写入的字节数。 | 2258e41f4b71Sopenharmony_ci 2259e41f4b71Sopenharmony_ci**错误码:** 2260e41f4b71Sopenharmony_ci 2261e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2262e41f4b71Sopenharmony_ci 2263e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2264e41f4b71Sopenharmony_ci| -------- | -------- | 2265e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2266e41f4b71Sopenharmony_ci| 10200001 | The value of "[offset/length]" is out of range. It must be >= 0 and <= buf.length. Received value is: [offset/length]. | 2267e41f4b71Sopenharmony_ci 2268e41f4b71Sopenharmony_ci**示例:** 2269e41f4b71Sopenharmony_ci 2270e41f4b71Sopenharmony_ci```ts 2271e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2272e41f4b71Sopenharmony_ci 2273e41f4b71Sopenharmony_cilet buf = buffer.alloc(256); 2274e41f4b71Sopenharmony_cilet len = buf.write('\u00bd + \u00bc = \u00be', 0); 2275e41f4b71Sopenharmony_ciconsole.log(`${len} bytes: ${buf.toString('utf-8', 0, len)}`); 2276e41f4b71Sopenharmony_ci// 打印: 12 bytes: ½ + ¼ = ¾ 2277e41f4b71Sopenharmony_ci 2278e41f4b71Sopenharmony_cilet buffer1 = buffer.alloc(10); 2279e41f4b71Sopenharmony_cilet length = buffer1.write('abcd', 8); 2280e41f4b71Sopenharmony_ci``` 2281e41f4b71Sopenharmony_ci 2282e41f4b71Sopenharmony_ci### writeBigInt64BE 2283e41f4b71Sopenharmony_ci 2284e41f4b71Sopenharmony_ciwriteBigInt64BE(value: bigint, offset?: number): number 2285e41f4b71Sopenharmony_ci 2286e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入有符号的大端序64位BigInt型数据value。 2287e41f4b71Sopenharmony_ci 2288e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2289e41f4b71Sopenharmony_ci 2290e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2291e41f4b71Sopenharmony_ci 2292e41f4b71Sopenharmony_ci**参数:** 2293e41f4b71Sopenharmony_ci 2294e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2295e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2296e41f4b71Sopenharmony_ci| value | bigint | 是 | 写入Buffer的数据。 | 2297e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2298e41f4b71Sopenharmony_ci 2299e41f4b71Sopenharmony_ci 2300e41f4b71Sopenharmony_ci**返回值:** 2301e41f4b71Sopenharmony_ci 2302e41f4b71Sopenharmony_ci| 类型 | 说明 | 2303e41f4b71Sopenharmony_ci| -------- | -------- | 2304e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2305e41f4b71Sopenharmony_ci 2306e41f4b71Sopenharmony_ci**错误码:** 2307e41f4b71Sopenharmony_ci 2308e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2309e41f4b71Sopenharmony_ci 2310e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2311e41f4b71Sopenharmony_ci| -------- | -------- | 2312e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2313e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2314e41f4b71Sopenharmony_ci 2315e41f4b71Sopenharmony_ci**示例:** 2316e41f4b71Sopenharmony_ci 2317e41f4b71Sopenharmony_ci```ts 2318e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2319e41f4b71Sopenharmony_ci 2320e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2321e41f4b71Sopenharmony_cilet result = buf.writeBigInt64BE(BigInt(0x0102030405060708), 0); 2322e41f4b71Sopenharmony_ci``` 2323e41f4b71Sopenharmony_ci 2324e41f4b71Sopenharmony_ci### writeBigInt64LE 2325e41f4b71Sopenharmony_ci 2326e41f4b71Sopenharmony_ciwriteBigInt64LE(value: bigint, offset?: number): number 2327e41f4b71Sopenharmony_ci 2328e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入有符号的小端序64位BigInt型数据value。 2329e41f4b71Sopenharmony_ci 2330e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2331e41f4b71Sopenharmony_ci 2332e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2333e41f4b71Sopenharmony_ci 2334e41f4b71Sopenharmony_ci**参数:** 2335e41f4b71Sopenharmony_ci 2336e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2337e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2338e41f4b71Sopenharmony_ci| value | bigint | 是 | 写入Buffer的数据。 | 2339e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2340e41f4b71Sopenharmony_ci 2341e41f4b71Sopenharmony_ci 2342e41f4b71Sopenharmony_ci**返回值:** 2343e41f4b71Sopenharmony_ci 2344e41f4b71Sopenharmony_ci| 类型 | 说明 | 2345e41f4b71Sopenharmony_ci| -------- | -------- | 2346e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2347e41f4b71Sopenharmony_ci 2348e41f4b71Sopenharmony_ci**错误码:** 2349e41f4b71Sopenharmony_ci 2350e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2351e41f4b71Sopenharmony_ci 2352e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2353e41f4b71Sopenharmony_ci| -------- | -------- | 2354e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2355e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2356e41f4b71Sopenharmony_ci 2357e41f4b71Sopenharmony_ci**示例:** 2358e41f4b71Sopenharmony_ci 2359e41f4b71Sopenharmony_ci```ts 2360e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2361e41f4b71Sopenharmony_ci 2362e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2363e41f4b71Sopenharmony_cilet result = buf.writeBigInt64LE(BigInt(0x0102030405060708), 0); 2364e41f4b71Sopenharmony_ci``` 2365e41f4b71Sopenharmony_ci 2366e41f4b71Sopenharmony_ci### writeBigUInt64BE 2367e41f4b71Sopenharmony_ci 2368e41f4b71Sopenharmony_ciwriteBigUInt64BE(value: bigint, offset?: number): number 2369e41f4b71Sopenharmony_ci 2370e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2371e41f4b71Sopenharmony_ci 2372e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入无符号的大端序64位BigUInt型数据value。 2373e41f4b71Sopenharmony_ci 2374e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2375e41f4b71Sopenharmony_ci 2376e41f4b71Sopenharmony_ci**参数:** 2377e41f4b71Sopenharmony_ci 2378e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2379e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2380e41f4b71Sopenharmony_ci| value | bigint | 是 | 写入Buffer的数据。 | 2381e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2382e41f4b71Sopenharmony_ci 2383e41f4b71Sopenharmony_ci 2384e41f4b71Sopenharmony_ci**返回值:** 2385e41f4b71Sopenharmony_ci 2386e41f4b71Sopenharmony_ci| 类型 | 说明 | 2387e41f4b71Sopenharmony_ci| -------- | -------- | 2388e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2389e41f4b71Sopenharmony_ci 2390e41f4b71Sopenharmony_ci**错误码:** 2391e41f4b71Sopenharmony_ci 2392e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2393e41f4b71Sopenharmony_ci 2394e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2395e41f4b71Sopenharmony_ci| -------- | -------- | 2396e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2397e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2398e41f4b71Sopenharmony_ci 2399e41f4b71Sopenharmony_ci**示例:** 2400e41f4b71Sopenharmony_ci 2401e41f4b71Sopenharmony_ci```ts 2402e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2403e41f4b71Sopenharmony_ci 2404e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2405e41f4b71Sopenharmony_cilet result = buf.writeBigUInt64BE(BigInt(0xdecafafecacefade), 0); 2406e41f4b71Sopenharmony_ci``` 2407e41f4b71Sopenharmony_ci 2408e41f4b71Sopenharmony_ci### writeBigUInt64LE 2409e41f4b71Sopenharmony_ci 2410e41f4b71Sopenharmony_ciwriteBigUInt64LE(value: bigint, offset?: number): number 2411e41f4b71Sopenharmony_ci 2412e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入无符号的小端序64位BigUInt型数据value。 2413e41f4b71Sopenharmony_ci 2414e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2415e41f4b71Sopenharmony_ci 2416e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2417e41f4b71Sopenharmony_ci 2418e41f4b71Sopenharmony_ci**参数:** 2419e41f4b71Sopenharmony_ci 2420e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2421e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2422e41f4b71Sopenharmony_ci| value | bigint | 是 | 写入Buffer的数据。 | 2423e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2424e41f4b71Sopenharmony_ci 2425e41f4b71Sopenharmony_ci 2426e41f4b71Sopenharmony_ci**返回值:** 2427e41f4b71Sopenharmony_ci 2428e41f4b71Sopenharmony_ci| 类型 | 说明 | 2429e41f4b71Sopenharmony_ci| -------- | -------- | 2430e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2431e41f4b71Sopenharmony_ci 2432e41f4b71Sopenharmony_ci**错误码:** 2433e41f4b71Sopenharmony_ci 2434e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2435e41f4b71Sopenharmony_ci 2436e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2437e41f4b71Sopenharmony_ci| -------- | -------- | 2438e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2439e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2440e41f4b71Sopenharmony_ci 2441e41f4b71Sopenharmony_ci**示例:** 2442e41f4b71Sopenharmony_ci 2443e41f4b71Sopenharmony_ci```ts 2444e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2445e41f4b71Sopenharmony_ci 2446e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2447e41f4b71Sopenharmony_cilet result = buf.writeBigUInt64LE(BigInt(0xdecafafecacefade), 0); 2448e41f4b71Sopenharmony_ci``` 2449e41f4b71Sopenharmony_ci 2450e41f4b71Sopenharmony_ci### writeDoubleBE 2451e41f4b71Sopenharmony_ci 2452e41f4b71Sopenharmony_ciwriteDoubleBE(value: number, offset?: number): number 2453e41f4b71Sopenharmony_ci 2454e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的64位双浮点型数据value。 2455e41f4b71Sopenharmony_ci 2456e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2457e41f4b71Sopenharmony_ci 2458e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2459e41f4b71Sopenharmony_ci 2460e41f4b71Sopenharmony_ci**参数:** 2461e41f4b71Sopenharmony_ci 2462e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2463e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2464e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2465e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2466e41f4b71Sopenharmony_ci 2467e41f4b71Sopenharmony_ci 2468e41f4b71Sopenharmony_ci**返回值:** 2469e41f4b71Sopenharmony_ci 2470e41f4b71Sopenharmony_ci| 类型 | 说明 | 2471e41f4b71Sopenharmony_ci| -------- | -------- | 2472e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2473e41f4b71Sopenharmony_ci 2474e41f4b71Sopenharmony_ci**错误码:** 2475e41f4b71Sopenharmony_ci 2476e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2477e41f4b71Sopenharmony_ci 2478e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2479e41f4b71Sopenharmony_ci| -------- | -------- | 2480e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2481e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] | 2482e41f4b71Sopenharmony_ci 2483e41f4b71Sopenharmony_ci**示例:** 2484e41f4b71Sopenharmony_ci 2485e41f4b71Sopenharmony_ci```ts 2486e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2487e41f4b71Sopenharmony_ci 2488e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2489e41f4b71Sopenharmony_cilet result = buf.writeDoubleBE(123.456, 0); 2490e41f4b71Sopenharmony_ci``` 2491e41f4b71Sopenharmony_ci 2492e41f4b71Sopenharmony_ci### writeDoubleLE 2493e41f4b71Sopenharmony_ci 2494e41f4b71Sopenharmony_ciwriteDoubleLE(value: number, offset?: number): number 2495e41f4b71Sopenharmony_ci 2496e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的64位双浮点型数据value。 2497e41f4b71Sopenharmony_ci 2498e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2499e41f4b71Sopenharmony_ci 2500e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2501e41f4b71Sopenharmony_ci 2502e41f4b71Sopenharmony_ci**参数:** 2503e41f4b71Sopenharmony_ci 2504e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2505e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2506e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2507e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 8。 | 2508e41f4b71Sopenharmony_ci 2509e41f4b71Sopenharmony_ci 2510e41f4b71Sopenharmony_ci**返回值:** 2511e41f4b71Sopenharmony_ci 2512e41f4b71Sopenharmony_ci| 类型 | 说明 | 2513e41f4b71Sopenharmony_ci| -------- | -------- | 2514e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2515e41f4b71Sopenharmony_ci 2516e41f4b71Sopenharmony_ci**错误码:** 2517e41f4b71Sopenharmony_ci 2518e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2519e41f4b71Sopenharmony_ci 2520e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2521e41f4b71Sopenharmony_ci| -------- | -------- | 2522e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2523e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] | 2524e41f4b71Sopenharmony_ci 2525e41f4b71Sopenharmony_ci**示例:** 2526e41f4b71Sopenharmony_ci 2527e41f4b71Sopenharmony_ci```ts 2528e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2529e41f4b71Sopenharmony_ci 2530e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2531e41f4b71Sopenharmony_cilet result = buf.writeDoubleLE(123.456, 0); 2532e41f4b71Sopenharmony_ci``` 2533e41f4b71Sopenharmony_ci 2534e41f4b71Sopenharmony_ci### writeFloatBE 2535e41f4b71Sopenharmony_ci 2536e41f4b71Sopenharmony_ciwriteFloatBE(value: number, offset?: number): number 2537e41f4b71Sopenharmony_ci 2538e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的32位浮点型数据value。 2539e41f4b71Sopenharmony_ci 2540e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2541e41f4b71Sopenharmony_ci 2542e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2543e41f4b71Sopenharmony_ci 2544e41f4b71Sopenharmony_ci**参数:** 2545e41f4b71Sopenharmony_ci 2546e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2547e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2548e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2549e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 2550e41f4b71Sopenharmony_ci 2551e41f4b71Sopenharmony_ci 2552e41f4b71Sopenharmony_ci**返回值:** 2553e41f4b71Sopenharmony_ci 2554e41f4b71Sopenharmony_ci| 类型 | 说明 | 2555e41f4b71Sopenharmony_ci| -------- | -------- | 2556e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2557e41f4b71Sopenharmony_ci 2558e41f4b71Sopenharmony_ci**错误码:** 2559e41f4b71Sopenharmony_ci 2560e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2561e41f4b71Sopenharmony_ci 2562e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2563e41f4b71Sopenharmony_ci| -------- | -------- | 2564e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2565e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] | 2566e41f4b71Sopenharmony_ci 2567e41f4b71Sopenharmony_ci**示例:** 2568e41f4b71Sopenharmony_ci 2569e41f4b71Sopenharmony_ci```ts 2570e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2571e41f4b71Sopenharmony_ci 2572e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2573e41f4b71Sopenharmony_cilet result = buf.writeFloatBE(0xcafebabe, 0); 2574e41f4b71Sopenharmony_ci``` 2575e41f4b71Sopenharmony_ci 2576e41f4b71Sopenharmony_ci 2577e41f4b71Sopenharmony_ci### writeFloatLE 2578e41f4b71Sopenharmony_ci 2579e41f4b71Sopenharmony_ciwriteFloatLE(value: number, offset?: number): number 2580e41f4b71Sopenharmony_ci 2581e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的32位浮点型数据value。 2582e41f4b71Sopenharmony_ci 2583e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2584e41f4b71Sopenharmony_ci 2585e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2586e41f4b71Sopenharmony_ci 2587e41f4b71Sopenharmony_ci**参数:** 2588e41f4b71Sopenharmony_ci 2589e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2590e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2591e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2592e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 2593e41f4b71Sopenharmony_ci 2594e41f4b71Sopenharmony_ci 2595e41f4b71Sopenharmony_ci**返回值:** 2596e41f4b71Sopenharmony_ci 2597e41f4b71Sopenharmony_ci| 类型 | 说明 | 2598e41f4b71Sopenharmony_ci| -------- | -------- | 2599e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2600e41f4b71Sopenharmony_ci 2601e41f4b71Sopenharmony_ci**错误码:** 2602e41f4b71Sopenharmony_ci 2603e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2604e41f4b71Sopenharmony_ci 2605e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2606e41f4b71Sopenharmony_ci| -------- | -------- | 2607e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2608e41f4b71Sopenharmony_ci| 10200001 | The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] | 2609e41f4b71Sopenharmony_ci 2610e41f4b71Sopenharmony_ci**示例:** 2611e41f4b71Sopenharmony_ci 2612e41f4b71Sopenharmony_ci```ts 2613e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2614e41f4b71Sopenharmony_ci 2615e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(8); 2616e41f4b71Sopenharmony_cilet result = buf.writeFloatLE(0xcafebabe, 0); 2617e41f4b71Sopenharmony_ci``` 2618e41f4b71Sopenharmony_ci 2619e41f4b71Sopenharmony_ci### writeInt8 2620e41f4b71Sopenharmony_ci 2621e41f4b71Sopenharmony_ciwriteInt8(value: number, offset?: number): number 2622e41f4b71Sopenharmony_ci 2623e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入8位有符号整型数据value。 2624e41f4b71Sopenharmony_ci 2625e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2626e41f4b71Sopenharmony_ci 2627e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2628e41f4b71Sopenharmony_ci 2629e41f4b71Sopenharmony_ci**参数:** 2630e41f4b71Sopenharmony_ci 2631e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2632e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2633e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2634e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 1。 | 2635e41f4b71Sopenharmony_ci 2636e41f4b71Sopenharmony_ci 2637e41f4b71Sopenharmony_ci**返回值:** 2638e41f4b71Sopenharmony_ci 2639e41f4b71Sopenharmony_ci| 类型 | 说明 | 2640e41f4b71Sopenharmony_ci| -------- | -------- | 2641e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2642e41f4b71Sopenharmony_ci 2643e41f4b71Sopenharmony_ci**错误码:** 2644e41f4b71Sopenharmony_ci 2645e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2646e41f4b71Sopenharmony_ci 2647e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2648e41f4b71Sopenharmony_ci| -------- | -------- | 2649e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2650e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2651e41f4b71Sopenharmony_ci 2652e41f4b71Sopenharmony_ci**示例:** 2653e41f4b71Sopenharmony_ci 2654e41f4b71Sopenharmony_ci```ts 2655e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2656e41f4b71Sopenharmony_ci 2657e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(2); 2658e41f4b71Sopenharmony_cilet result = buf.writeInt8(2, 0); 2659e41f4b71Sopenharmony_cilet result1 = buf.writeInt8(-2, 1); 2660e41f4b71Sopenharmony_ci``` 2661e41f4b71Sopenharmony_ci 2662e41f4b71Sopenharmony_ci 2663e41f4b71Sopenharmony_ci### writeInt16BE 2664e41f4b71Sopenharmony_ci 2665e41f4b71Sopenharmony_ciwriteInt16BE(value: number, offset?: number): number 2666e41f4b71Sopenharmony_ci 2667e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的16位有符号整型数据value。 2668e41f4b71Sopenharmony_ci 2669e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2670e41f4b71Sopenharmony_ci 2671e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2672e41f4b71Sopenharmony_ci 2673e41f4b71Sopenharmony_ci**参数:** 2674e41f4b71Sopenharmony_ci 2675e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2676e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2677e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2678e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 2。 | 2679e41f4b71Sopenharmony_ci 2680e41f4b71Sopenharmony_ci 2681e41f4b71Sopenharmony_ci**返回值:** 2682e41f4b71Sopenharmony_ci 2683e41f4b71Sopenharmony_ci| 类型 | 说明 | 2684e41f4b71Sopenharmony_ci| -------- | -------- | 2685e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2686e41f4b71Sopenharmony_ci 2687e41f4b71Sopenharmony_ci**错误码:** 2688e41f4b71Sopenharmony_ci 2689e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2690e41f4b71Sopenharmony_ci 2691e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2692e41f4b71Sopenharmony_ci| -------- | -------- | 2693e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2694e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2695e41f4b71Sopenharmony_ci 2696e41f4b71Sopenharmony_ci**示例:** 2697e41f4b71Sopenharmony_ci 2698e41f4b71Sopenharmony_ci```ts 2699e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2700e41f4b71Sopenharmony_ci 2701e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(2); 2702e41f4b71Sopenharmony_cilet result = buf.writeInt16BE(0x0102, 0); 2703e41f4b71Sopenharmony_ci``` 2704e41f4b71Sopenharmony_ci 2705e41f4b71Sopenharmony_ci 2706e41f4b71Sopenharmony_ci### writeInt16LE 2707e41f4b71Sopenharmony_ci 2708e41f4b71Sopenharmony_ciwriteInt16LE(value: number, offset?: number): number 2709e41f4b71Sopenharmony_ci 2710e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的16位有符号整型数据value。 2711e41f4b71Sopenharmony_ci 2712e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2713e41f4b71Sopenharmony_ci 2714e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2715e41f4b71Sopenharmony_ci 2716e41f4b71Sopenharmony_ci**参数:** 2717e41f4b71Sopenharmony_ci 2718e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2719e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2720e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2721e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 2。 | 2722e41f4b71Sopenharmony_ci 2723e41f4b71Sopenharmony_ci 2724e41f4b71Sopenharmony_ci**返回值:** 2725e41f4b71Sopenharmony_ci 2726e41f4b71Sopenharmony_ci| 类型 | 说明 | 2727e41f4b71Sopenharmony_ci| -------- | -------- | 2728e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2729e41f4b71Sopenharmony_ci 2730e41f4b71Sopenharmony_ci**错误码:** 2731e41f4b71Sopenharmony_ci 2732e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2733e41f4b71Sopenharmony_ci 2734e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2735e41f4b71Sopenharmony_ci| -------- | -------- | 2736e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2737e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2738e41f4b71Sopenharmony_ci 2739e41f4b71Sopenharmony_ci**示例:** 2740e41f4b71Sopenharmony_ci 2741e41f4b71Sopenharmony_ci```ts 2742e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2743e41f4b71Sopenharmony_ci 2744e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(2); 2745e41f4b71Sopenharmony_cilet result = buf.writeInt16LE(0x0304, 0); 2746e41f4b71Sopenharmony_ci``` 2747e41f4b71Sopenharmony_ci 2748e41f4b71Sopenharmony_ci### writeInt32BE 2749e41f4b71Sopenharmony_ci 2750e41f4b71Sopenharmony_ciwriteInt32BE(value: number, offset?: number): number 2751e41f4b71Sopenharmony_ci 2752e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的32位有符号整型数据value。 2753e41f4b71Sopenharmony_ci 2754e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2755e41f4b71Sopenharmony_ci 2756e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2757e41f4b71Sopenharmony_ci 2758e41f4b71Sopenharmony_ci**参数:** 2759e41f4b71Sopenharmony_ci 2760e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2761e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2762e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2763e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 2764e41f4b71Sopenharmony_ci 2765e41f4b71Sopenharmony_ci 2766e41f4b71Sopenharmony_ci**返回值:** 2767e41f4b71Sopenharmony_ci 2768e41f4b71Sopenharmony_ci| 类型 | 说明 | 2769e41f4b71Sopenharmony_ci| -------- | -------- | 2770e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2771e41f4b71Sopenharmony_ci 2772e41f4b71Sopenharmony_ci**错误码:** 2773e41f4b71Sopenharmony_ci 2774e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2775e41f4b71Sopenharmony_ci 2776e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2777e41f4b71Sopenharmony_ci| -------- | -------- | 2778e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2779e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2780e41f4b71Sopenharmony_ci 2781e41f4b71Sopenharmony_ci**示例:** 2782e41f4b71Sopenharmony_ci 2783e41f4b71Sopenharmony_ci```ts 2784e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2785e41f4b71Sopenharmony_ci 2786e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 2787e41f4b71Sopenharmony_cilet result = buf.writeInt32BE(0x01020304, 0); 2788e41f4b71Sopenharmony_ci``` 2789e41f4b71Sopenharmony_ci 2790e41f4b71Sopenharmony_ci 2791e41f4b71Sopenharmony_ci### writeInt32LE 2792e41f4b71Sopenharmony_ci 2793e41f4b71Sopenharmony_ciwriteInt32LE(value: number, offset?: number): number 2794e41f4b71Sopenharmony_ci 2795e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的32位有符号整型数据value。 2796e41f4b71Sopenharmony_ci 2797e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2798e41f4b71Sopenharmony_ci 2799e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2800e41f4b71Sopenharmony_ci 2801e41f4b71Sopenharmony_ci**参数:** 2802e41f4b71Sopenharmony_ci 2803e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2804e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2805e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2806e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 2807e41f4b71Sopenharmony_ci 2808e41f4b71Sopenharmony_ci 2809e41f4b71Sopenharmony_ci**返回值:** 2810e41f4b71Sopenharmony_ci 2811e41f4b71Sopenharmony_ci| 类型 | 说明 | 2812e41f4b71Sopenharmony_ci| -------- | -------- | 2813e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2814e41f4b71Sopenharmony_ci 2815e41f4b71Sopenharmony_ci**错误码:** 2816e41f4b71Sopenharmony_ci 2817e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2818e41f4b71Sopenharmony_ci 2819e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2820e41f4b71Sopenharmony_ci| -------- | -------- | 2821e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2822e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2823e41f4b71Sopenharmony_ci 2824e41f4b71Sopenharmony_ci**示例:** 2825e41f4b71Sopenharmony_ci 2826e41f4b71Sopenharmony_ci```ts 2827e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2828e41f4b71Sopenharmony_ci 2829e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 2830e41f4b71Sopenharmony_cilet result = buf.writeInt32LE(0x05060708, 0); 2831e41f4b71Sopenharmony_ci``` 2832e41f4b71Sopenharmony_ci 2833e41f4b71Sopenharmony_ci### writeIntBE 2834e41f4b71Sopenharmony_ci 2835e41f4b71Sopenharmony_ciwriteIntBE(value: number, offset: number, byteLength: number): number 2836e41f4b71Sopenharmony_ci 2837e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的有符号value数据,value字节长度为byteLength。 2838e41f4b71Sopenharmony_ci 2839e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2840e41f4b71Sopenharmony_ci 2841e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2842e41f4b71Sopenharmony_ci 2843e41f4b71Sopenharmony_ci**参数:** 2844e41f4b71Sopenharmony_ci 2845e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2846e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2847e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2848e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - byteLength。 | 2849e41f4b71Sopenharmony_ci| byteLength | number | 是 | 要写入的字节数。 | 2850e41f4b71Sopenharmony_ci 2851e41f4b71Sopenharmony_ci 2852e41f4b71Sopenharmony_ci**返回值:** 2853e41f4b71Sopenharmony_ci 2854e41f4b71Sopenharmony_ci| 类型 | 说明 | 2855e41f4b71Sopenharmony_ci| -------- | -------- | 2856e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2857e41f4b71Sopenharmony_ci 2858e41f4b71Sopenharmony_ci**错误码:** 2859e41f4b71Sopenharmony_ci 2860e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2861e41f4b71Sopenharmony_ci 2862e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2863e41f4b71Sopenharmony_ci| -------- | -------- | 2864e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2865e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2866e41f4b71Sopenharmony_ci 2867e41f4b71Sopenharmony_ci**示例:** 2868e41f4b71Sopenharmony_ci 2869e41f4b71Sopenharmony_ci```ts 2870e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2871e41f4b71Sopenharmony_ci 2872e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(6); 2873e41f4b71Sopenharmony_cilet result = buf.writeIntBE(0x1234567890ab, 0, 6); 2874e41f4b71Sopenharmony_ci``` 2875e41f4b71Sopenharmony_ci 2876e41f4b71Sopenharmony_ci 2877e41f4b71Sopenharmony_ci### writeIntLE 2878e41f4b71Sopenharmony_ci 2879e41f4b71Sopenharmony_ciwriteIntLE(value: number, offset: number, byteLength: number): number 2880e41f4b71Sopenharmony_ci 2881e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的有符号value数据,value字节长度为byteLength。 2882e41f4b71Sopenharmony_ci 2883e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2884e41f4b71Sopenharmony_ci 2885e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2886e41f4b71Sopenharmony_ci 2887e41f4b71Sopenharmony_ci**参数:** 2888e41f4b71Sopenharmony_ci 2889e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2890e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2891e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2892e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - byteLength。 | 2893e41f4b71Sopenharmony_ci| byteLength | number | 是 | 要写入的字节数。 | 2894e41f4b71Sopenharmony_ci 2895e41f4b71Sopenharmony_ci 2896e41f4b71Sopenharmony_ci**返回值:** 2897e41f4b71Sopenharmony_ci 2898e41f4b71Sopenharmony_ci| 类型 | 说明 | 2899e41f4b71Sopenharmony_ci| -------- | -------- | 2900e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2901e41f4b71Sopenharmony_ci 2902e41f4b71Sopenharmony_ci**错误码:** 2903e41f4b71Sopenharmony_ci 2904e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2905e41f4b71Sopenharmony_ci 2906e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2907e41f4b71Sopenharmony_ci| -------- | -------- | 2908e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2909e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2910e41f4b71Sopenharmony_ci 2911e41f4b71Sopenharmony_ci**示例:** 2912e41f4b71Sopenharmony_ci 2913e41f4b71Sopenharmony_ci```ts 2914e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2915e41f4b71Sopenharmony_ci 2916e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(6); 2917e41f4b71Sopenharmony_cilet result = buf.writeIntLE(0x1234567890ab, 0, 6); 2918e41f4b71Sopenharmony_ci``` 2919e41f4b71Sopenharmony_ci 2920e41f4b71Sopenharmony_ci### writeUInt8 2921e41f4b71Sopenharmony_ci 2922e41f4b71Sopenharmony_ciwriteUInt8(value: number, offset?: number): number 2923e41f4b71Sopenharmony_ci 2924e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入8位无符号整型数据value。 2925e41f4b71Sopenharmony_ci 2926e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2927e41f4b71Sopenharmony_ci 2928e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2929e41f4b71Sopenharmony_ci 2930e41f4b71Sopenharmony_ci**参数:** 2931e41f4b71Sopenharmony_ci 2932e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2933e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2934e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2935e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 1。 | 2936e41f4b71Sopenharmony_ci 2937e41f4b71Sopenharmony_ci 2938e41f4b71Sopenharmony_ci**返回值:** 2939e41f4b71Sopenharmony_ci 2940e41f4b71Sopenharmony_ci| 类型 | 说明 | 2941e41f4b71Sopenharmony_ci| -------- | -------- | 2942e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2943e41f4b71Sopenharmony_ci 2944e41f4b71Sopenharmony_ci**错误码:** 2945e41f4b71Sopenharmony_ci 2946e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2947e41f4b71Sopenharmony_ci 2948e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2949e41f4b71Sopenharmony_ci| -------- | -------- | 2950e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2951e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2952e41f4b71Sopenharmony_ci 2953e41f4b71Sopenharmony_ci**示例:** 2954e41f4b71Sopenharmony_ci 2955e41f4b71Sopenharmony_ci```ts 2956e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 2957e41f4b71Sopenharmony_ci 2958e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 2959e41f4b71Sopenharmony_cilet result = buf.writeUInt8(0x3, 0); 2960e41f4b71Sopenharmony_cilet result1 = buf.writeUInt8(0x4, 1); 2961e41f4b71Sopenharmony_cilet result2 = buf.writeUInt8(0x23, 2); 2962e41f4b71Sopenharmony_cilet result3 = buf.writeUInt8(0x42, 3); 2963e41f4b71Sopenharmony_ci``` 2964e41f4b71Sopenharmony_ci 2965e41f4b71Sopenharmony_ci### writeUInt16BE 2966e41f4b71Sopenharmony_ci 2967e41f4b71Sopenharmony_ciwriteUInt16BE(value: number, offset?: number): number 2968e41f4b71Sopenharmony_ci 2969e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的16位无符号整型数据value。 2970e41f4b71Sopenharmony_ci 2971e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 2972e41f4b71Sopenharmony_ci 2973e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 2974e41f4b71Sopenharmony_ci 2975e41f4b71Sopenharmony_ci**参数:** 2976e41f4b71Sopenharmony_ci 2977e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 2978e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 2979e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 2980e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值为0。取值范围:0 <= offset <= Buffer.length - 2。 | 2981e41f4b71Sopenharmony_ci 2982e41f4b71Sopenharmony_ci 2983e41f4b71Sopenharmony_ci**返回值:** 2984e41f4b71Sopenharmony_ci 2985e41f4b71Sopenharmony_ci| 类型 | 说明 | 2986e41f4b71Sopenharmony_ci| -------- | -------- | 2987e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 2988e41f4b71Sopenharmony_ci 2989e41f4b71Sopenharmony_ci**错误码:** 2990e41f4b71Sopenharmony_ci 2991e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 2992e41f4b71Sopenharmony_ci 2993e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 2994e41f4b71Sopenharmony_ci| -------- | -------- | 2995e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2996e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 2997e41f4b71Sopenharmony_ci 2998e41f4b71Sopenharmony_ci**示例:** 2999e41f4b71Sopenharmony_ci 3000e41f4b71Sopenharmony_ci```ts 3001e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3002e41f4b71Sopenharmony_ci 3003e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 3004e41f4b71Sopenharmony_cilet result = buf.writeUInt16BE(0xdead, 0); 3005e41f4b71Sopenharmony_cilet result1 = buf.writeUInt16BE(0xbeef, 2); 3006e41f4b71Sopenharmony_ci``` 3007e41f4b71Sopenharmony_ci 3008e41f4b71Sopenharmony_ci### writeUInt16LE 3009e41f4b71Sopenharmony_ci 3010e41f4b71Sopenharmony_ciwriteUInt16LE(value: number, offset?: number): number 3011e41f4b71Sopenharmony_ci 3012e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的16位无符号整型数据value。 3013e41f4b71Sopenharmony_ci 3014e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3015e41f4b71Sopenharmony_ci 3016e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3017e41f4b71Sopenharmony_ci 3018e41f4b71Sopenharmony_ci**参数:** 3019e41f4b71Sopenharmony_ci 3020e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3021e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3022e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 3023e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 2。 | 3024e41f4b71Sopenharmony_ci 3025e41f4b71Sopenharmony_ci 3026e41f4b71Sopenharmony_ci**返回值:** 3027e41f4b71Sopenharmony_ci 3028e41f4b71Sopenharmony_ci| 类型 | 说明 | 3029e41f4b71Sopenharmony_ci| -------- | -------- | 3030e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 3031e41f4b71Sopenharmony_ci 3032e41f4b71Sopenharmony_ci**错误码:** 3033e41f4b71Sopenharmony_ci 3034e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 3035e41f4b71Sopenharmony_ci 3036e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3037e41f4b71Sopenharmony_ci| -------- | -------- | 3038e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3039e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 3040e41f4b71Sopenharmony_ci 3041e41f4b71Sopenharmony_ci**示例:** 3042e41f4b71Sopenharmony_ci 3043e41f4b71Sopenharmony_ci```ts 3044e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3045e41f4b71Sopenharmony_ci 3046e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 3047e41f4b71Sopenharmony_cilet result = buf.writeUInt16LE(0xdead, 0); 3048e41f4b71Sopenharmony_cilet result1 = buf.writeUInt16LE(0xbeef, 2); 3049e41f4b71Sopenharmony_ci``` 3050e41f4b71Sopenharmony_ci 3051e41f4b71Sopenharmony_ci### writeUInt32BE 3052e41f4b71Sopenharmony_ci 3053e41f4b71Sopenharmony_ciwriteUInt32BE(value: number, offset?: number): number 3054e41f4b71Sopenharmony_ci 3055e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的32位无符号整型数据value。 3056e41f4b71Sopenharmony_ci 3057e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3058e41f4b71Sopenharmony_ci 3059e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3060e41f4b71Sopenharmony_ci 3061e41f4b71Sopenharmony_ci**参数:** 3062e41f4b71Sopenharmony_ci 3063e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3064e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3065e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 3066e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 3067e41f4b71Sopenharmony_ci 3068e41f4b71Sopenharmony_ci 3069e41f4b71Sopenharmony_ci**返回值:** 3070e41f4b71Sopenharmony_ci 3071e41f4b71Sopenharmony_ci| 类型 | 说明 | 3072e41f4b71Sopenharmony_ci| -------- | -------- | 3073e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 3074e41f4b71Sopenharmony_ci 3075e41f4b71Sopenharmony_ci**错误码:** 3076e41f4b71Sopenharmony_ci 3077e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 3078e41f4b71Sopenharmony_ci 3079e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3080e41f4b71Sopenharmony_ci| -------- | -------- | 3081e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3082e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 3083e41f4b71Sopenharmony_ci 3084e41f4b71Sopenharmony_ci**示例:** 3085e41f4b71Sopenharmony_ci 3086e41f4b71Sopenharmony_ci```ts 3087e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3088e41f4b71Sopenharmony_ci 3089e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 3090e41f4b71Sopenharmony_cilet result = buf.writeUInt32BE(0xfeedface, 0); 3091e41f4b71Sopenharmony_ci``` 3092e41f4b71Sopenharmony_ci 3093e41f4b71Sopenharmony_ci### writeUInt32LE 3094e41f4b71Sopenharmony_ci 3095e41f4b71Sopenharmony_ciwriteUInt32LE(value: number, offset?: number): number 3096e41f4b71Sopenharmony_ci 3097e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的32位无符号整型数据value。 3098e41f4b71Sopenharmony_ci 3099e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3100e41f4b71Sopenharmony_ci 3101e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3102e41f4b71Sopenharmony_ci 3103e41f4b71Sopenharmony_ci**参数:** 3104e41f4b71Sopenharmony_ci 3105e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3106e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3107e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer对象的数字。 | 3108e41f4b71Sopenharmony_ci| offset | number | 否 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - 4。 | 3109e41f4b71Sopenharmony_ci 3110e41f4b71Sopenharmony_ci 3111e41f4b71Sopenharmony_ci**返回值:** 3112e41f4b71Sopenharmony_ci 3113e41f4b71Sopenharmony_ci| 类型 | 说明 | 3114e41f4b71Sopenharmony_ci| -------- | -------- | 3115e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 3116e41f4b71Sopenharmony_ci 3117e41f4b71Sopenharmony_ci**错误码:** 3118e41f4b71Sopenharmony_ci 3119e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 3120e41f4b71Sopenharmony_ci 3121e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3122e41f4b71Sopenharmony_ci| -------- | -------- | 3123e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3124e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 3125e41f4b71Sopenharmony_ci 3126e41f4b71Sopenharmony_ci**示例:** 3127e41f4b71Sopenharmony_ci 3128e41f4b71Sopenharmony_ci```ts 3129e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3130e41f4b71Sopenharmony_ci 3131e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(4); 3132e41f4b71Sopenharmony_cilet result = buf.writeUInt32LE(0xfeedface, 0); 3133e41f4b71Sopenharmony_ci``` 3134e41f4b71Sopenharmony_ci 3135e41f4b71Sopenharmony_ci### writeUIntBE 3136e41f4b71Sopenharmony_ci 3137e41f4b71Sopenharmony_ciwriteUIntBE(value: number, offset: number, byteLength: number): number 3138e41f4b71Sopenharmony_ci 3139e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入大端序的无符号value数据,value字节长度为byteLength。 3140e41f4b71Sopenharmony_ci 3141e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3142e41f4b71Sopenharmony_ci 3143e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3144e41f4b71Sopenharmony_ci 3145e41f4b71Sopenharmony_ci**参数:** 3146e41f4b71Sopenharmony_ci 3147e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3148e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3149e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 3150e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - byteLength。 | 3151e41f4b71Sopenharmony_ci| byteLength | number | 是 | 要写入的字节数。 | 3152e41f4b71Sopenharmony_ci 3153e41f4b71Sopenharmony_ci 3154e41f4b71Sopenharmony_ci**返回值:** 3155e41f4b71Sopenharmony_ci 3156e41f4b71Sopenharmony_ci| 类型 | 说明 | 3157e41f4b71Sopenharmony_ci| -------- | -------- | 3158e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 3159e41f4b71Sopenharmony_ci 3160e41f4b71Sopenharmony_ci**错误码:** 3161e41f4b71Sopenharmony_ci 3162e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 3163e41f4b71Sopenharmony_ci 3164e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3165e41f4b71Sopenharmony_ci| -------- | -------- | 3166e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3167e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 3168e41f4b71Sopenharmony_ci 3169e41f4b71Sopenharmony_ci**示例:** 3170e41f4b71Sopenharmony_ci 3171e41f4b71Sopenharmony_ci```ts 3172e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3173e41f4b71Sopenharmony_ci 3174e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(6); 3175e41f4b71Sopenharmony_cilet result = buf.writeUIntBE(0x1234567890ab, 0, 6); 3176e41f4b71Sopenharmony_ci``` 3177e41f4b71Sopenharmony_ci 3178e41f4b71Sopenharmony_ci### writeUIntLE 3179e41f4b71Sopenharmony_ci 3180e41f4b71Sopenharmony_ciwriteUIntLE(value: number, offset: number, byteLength: number): number 3181e41f4b71Sopenharmony_ci 3182e41f4b71Sopenharmony_ci从Buffer对象的offset偏移写入小端序的无符号value数据,value字节长度为byteLength。 3183e41f4b71Sopenharmony_ci 3184e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3185e41f4b71Sopenharmony_ci 3186e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3187e41f4b71Sopenharmony_ci 3188e41f4b71Sopenharmony_ci**参数:** 3189e41f4b71Sopenharmony_ci 3190e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3191e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3192e41f4b71Sopenharmony_ci| value | number | 是 | 写入Buffer的数据。 | 3193e41f4b71Sopenharmony_ci| offset | number | 是 | 偏移量。 默认值: 0。取值范围:0 <= offset <= Buffer.length - byteLength。 | 3194e41f4b71Sopenharmony_ci| byteLength | number | 是 | 要写入的字节数。 | 3195e41f4b71Sopenharmony_ci 3196e41f4b71Sopenharmony_ci 3197e41f4b71Sopenharmony_ci**返回值:** 3198e41f4b71Sopenharmony_ci 3199e41f4b71Sopenharmony_ci| 类型 | 说明 | 3200e41f4b71Sopenharmony_ci| -------- | -------- | 3201e41f4b71Sopenharmony_ci| number | 偏移量offset加上写入的字节数。 | 3202e41f4b71Sopenharmony_ci 3203e41f4b71Sopenharmony_ci**错误码:** 3204e41f4b71Sopenharmony_ci 3205e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。 3206e41f4b71Sopenharmony_ci 3207e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3208e41f4b71Sopenharmony_ci| -------- | -------- | 3209e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3210e41f4b71Sopenharmony_ci| 10200001 | The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] | 3211e41f4b71Sopenharmony_ci 3212e41f4b71Sopenharmony_ci**示例:** 3213e41f4b71Sopenharmony_ci 3214e41f4b71Sopenharmony_ci```ts 3215e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3216e41f4b71Sopenharmony_ci 3217e41f4b71Sopenharmony_cilet buf = buffer.allocUninitializedFromPool(6); 3218e41f4b71Sopenharmony_cilet result = buf.writeUIntLE(0x1234567890ab, 0, 6); 3219e41f4b71Sopenharmony_ci``` 3220e41f4b71Sopenharmony_ci 3221e41f4b71Sopenharmony_ci## Blob 3222e41f4b71Sopenharmony_ci 3223e41f4b71Sopenharmony_ci### 属性 3224e41f4b71Sopenharmony_ci 3225e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3226e41f4b71Sopenharmony_ci 3227e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3228e41f4b71Sopenharmony_ci 3229e41f4b71Sopenharmony_ci| 名称 | 类型 | 可读 | 可写 | 说明 | 3230e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 3231e41f4b71Sopenharmony_ci| size | number | 是 | 否 | Blob实例的总字节大小。 | 3232e41f4b71Sopenharmony_ci| type | string | 是 | 否 | Blob实例的内容类型。 | 3233e41f4b71Sopenharmony_ci 3234e41f4b71Sopenharmony_ci### constructor 3235e41f4b71Sopenharmony_ci 3236e41f4b71Sopenharmony_ciconstructor(sources: string[] | ArrayBuffer[] | TypedArray[] | DataView[] | Blob[] , options?: Object) 3237e41f4b71Sopenharmony_ci 3238e41f4b71Sopenharmony_ciBlob的构造函数。 3239e41f4b71Sopenharmony_ci 3240e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3241e41f4b71Sopenharmony_ci 3242e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3243e41f4b71Sopenharmony_ci 3244e41f4b71Sopenharmony_ci**参数:** 3245e41f4b71Sopenharmony_ci 3246e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3247e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3248e41f4b71Sopenharmony_ci| sources | string[] \| ArrayBuffer[] \| TypedArray[] \| DataView[] \| Blob[] | 是 | Blob实例的数据源。 | 3249e41f4b71Sopenharmony_ci| options | Object | 否 | options:<br/>- endings:含义为结束符'\n'的字符串如何被输出,为'transparent'或'native'。native代表行结束符会跟随系统。'transparent'代表会保持Blob中保存的结束符不变。此参数非必填,默认值为'transparent'。<br/>- type:Blob内容类型。其目的是让类型传达数据的MIME媒体类型,但是不执行类型格式的验证。此参数非必填,默认参数为''。 | 3250e41f4b71Sopenharmony_ci 3251e41f4b71Sopenharmony_ci**错误码:** 3252e41f4b71Sopenharmony_ci 3253e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 3254e41f4b71Sopenharmony_ci 3255e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 3256e41f4b71Sopenharmony_ci| -------- | -------- | 3257e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3258e41f4b71Sopenharmony_ci 3259e41f4b71Sopenharmony_ci**示例:** 3260e41f4b71Sopenharmony_ci```ts 3261e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3262e41f4b71Sopenharmony_ci 3263e41f4b71Sopenharmony_cilet blob: buffer.Blob = new buffer.Blob(['a', 'b', 'c']); 3264e41f4b71Sopenharmony_ci 3265e41f4b71Sopenharmony_ciclass option { 3266e41f4b71Sopenharmony_ci endings: string = ""; 3267e41f4b71Sopenharmony_ci type: string = ""; 3268e41f4b71Sopenharmony_ci} 3269e41f4b71Sopenharmony_cilet o1: option = {endings:'native', type: 'MIME'} 3270e41f4b71Sopenharmony_cilet blob1: buffer.Blob = new buffer.Blob(['a', 'b', 'c'], o1); 3271e41f4b71Sopenharmony_ci``` 3272e41f4b71Sopenharmony_ci 3273e41f4b71Sopenharmony_ci### arrayBuffer 3274e41f4b71Sopenharmony_ci 3275e41f4b71Sopenharmony_ciarrayBuffer(): Promise<ArrayBuffer> 3276e41f4b71Sopenharmony_ci 3277e41f4b71Sopenharmony_ci将Blob中的数据放入到ArrayBuffer中,并返回一个Promise。 3278e41f4b71Sopenharmony_ci 3279e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3280e41f4b71Sopenharmony_ci 3281e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3282e41f4b71Sopenharmony_ci 3283e41f4b71Sopenharmony_ci**返回值:** 3284e41f4b71Sopenharmony_ci| 类型 | 说明 | 3285e41f4b71Sopenharmony_ci| -------- | -------- | 3286e41f4b71Sopenharmony_ci| Promise<ArrayBuffer> | Promise对象,返回包含Blob数据的ArrayBuffer。 | 3287e41f4b71Sopenharmony_ci 3288e41f4b71Sopenharmony_ci**示例:** 3289e41f4b71Sopenharmony_ci```ts 3290e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3291e41f4b71Sopenharmony_ci 3292e41f4b71Sopenharmony_cilet blob: buffer.Blob = new buffer.Blob(['a', 'b', 'c']); 3293e41f4b71Sopenharmony_cilet pro = blob.arrayBuffer(); 3294e41f4b71Sopenharmony_cipro.then((val: ArrayBuffer) => { 3295e41f4b71Sopenharmony_ci let uintarr: Uint8Array = new Uint8Array(val); 3296e41f4b71Sopenharmony_ci console.log(uintarr.toString()); 3297e41f4b71Sopenharmony_ci}); 3298e41f4b71Sopenharmony_ci``` 3299e41f4b71Sopenharmony_ci### slice 3300e41f4b71Sopenharmony_ci 3301e41f4b71Sopenharmony_cislice(start?: number, end?: number, type?: string): Blob 3302e41f4b71Sopenharmony_ci 3303e41f4b71Sopenharmony_ci创建并返回一个复制原Blob对象中指定数据长度的Blob新对象。 3304e41f4b71Sopenharmony_ci 3305e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3306e41f4b71Sopenharmony_ci 3307e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3308e41f4b71Sopenharmony_ci 3309e41f4b71Sopenharmony_ci**参数:** 3310e41f4b71Sopenharmony_ci 3311e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 3312e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 3313e41f4b71Sopenharmony_ci| start | number | 否 | 起始位置。默认值为0。 | 3314e41f4b71Sopenharmony_ci| end | number | 否 | 结束位置。默认值为原Blob对象中的数据长度。 | 3315e41f4b71Sopenharmony_ci| type | string | 否 | 内容类型。默认值为''。 | 3316e41f4b71Sopenharmony_ci 3317e41f4b71Sopenharmony_ci**返回值:** 3318e41f4b71Sopenharmony_ci| 类型 | 说明 | 3319e41f4b71Sopenharmony_ci| -------- | -------- | 3320e41f4b71Sopenharmony_ci| Blob | 新的Blob实例对象。 | 3321e41f4b71Sopenharmony_ci 3322e41f4b71Sopenharmony_ci**示例:** 3323e41f4b71Sopenharmony_ci```ts 3324e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3325e41f4b71Sopenharmony_ci 3326e41f4b71Sopenharmony_cilet blob: buffer.Blob = new buffer.Blob(['a', 'b', 'c']); 3327e41f4b71Sopenharmony_cilet blob2 = blob.slice(0, 2); 3328e41f4b71Sopenharmony_cilet blob3 = blob.slice(0, 2, "MIME"); 3329e41f4b71Sopenharmony_ci``` 3330e41f4b71Sopenharmony_ci 3331e41f4b71Sopenharmony_ci### text 3332e41f4b71Sopenharmony_ci 3333e41f4b71Sopenharmony_citext(): Promise<string> 3334e41f4b71Sopenharmony_ci 3335e41f4b71Sopenharmony_ci使用UTF8进行解码并返回一个文本。使用Promise异步回调。 3336e41f4b71Sopenharmony_ci 3337e41f4b71Sopenharmony_ci**原子化服务API**:从API version 11 开始,该接口支持在原子化服务中使用。 3338e41f4b71Sopenharmony_ci 3339e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Utils.Lang 3340e41f4b71Sopenharmony_ci 3341e41f4b71Sopenharmony_ci**返回值:** 3342e41f4b71Sopenharmony_ci| 类型 | 说明 | 3343e41f4b71Sopenharmony_ci| -------- | -------- | 3344e41f4b71Sopenharmony_ci| Promise<string> | Promise对象,返回包含以UTF8解码的文本。 | 3345e41f4b71Sopenharmony_ci 3346e41f4b71Sopenharmony_ci**示例:** 3347e41f4b71Sopenharmony_ci```ts 3348e41f4b71Sopenharmony_ciimport { buffer } from '@kit.ArkTS'; 3349e41f4b71Sopenharmony_ci 3350e41f4b71Sopenharmony_cilet blob: buffer.Blob = new buffer.Blob(['a', 'b', 'c']); 3351e41f4b71Sopenharmony_cilet pro = blob.text(); 3352e41f4b71Sopenharmony_cipro.then((val: string) => { 3353e41f4b71Sopenharmony_ci console.log(val); 3354e41f4b71Sopenharmony_ci}); 3355e41f4b71Sopenharmony_ci```