提交 45d3970c 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 96635ea1
# Connectivity
- Network Management
- [Network Management Overview](net-mgmt-overview.md)
- [HTTP Data Request](http-request.md)
- [WebSocket Connection](websocket-connection.md)
- [Socket Connection](socket-connection.md)
- [Network Management Overview](net-mgmt-overview.md)
- [HTTP Data Request](http-request.md)
- [WebSocket Connection](websocket-connection.md)
- [Socket Connection](socket-connection.md)
- IPC & RPC
- [IPC & RPC Overview](ipc-rpc-overview.md)
- [IPC & RPC Development](ipc-rpc-development-guideline.md)
- [Subscribing to State Changes of a Remote Object](subscribe-remote-state.md)
- [IPC & RPC Overview](ipc-rpc-overview.md)
- [IPC & RPC Development](ipc-rpc-development-guideline.md)
- [Subscribing to State Changes of a Remote Object](subscribe-remote-state.md)
# Buffer
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A **Buffer** object represents a fixed-length sequence of bytes. It is used to store binary data.
......@@ -14,6 +13,26 @@ You can use the APIs provided by the **Buffer** module to process images and a l
import buffer from '@ohos.buffer';
```
## BufferEncoding
Enumerates the supported encoding formats of strings.
**System capability**: SystemCapability.Utils.Lang
| Encoding Format | Description |
| ------- | -------------------- |
| ascii | ASCII format. |
| utf8 | UTF-8 |
| utf-8 | UTF-8 format.|
| utf16le | UTF-16LE format.|
| ucs2 | UTF-16LE format.|
| ucs-2 | UTF-16LE format.|
| base64 | Base64 format.|
| base64url | Base64 format.|
| latin1 | ASCII format.|
| binary | Binary format.|
| hex | Hexadecimal format.|
## Buffer
### Attributes
......@@ -26,6 +45,26 @@ import buffer from '@ohos.buffer';
| buffer | ArrayBuffer | Yes| No| **ArrayBuffer** object.|
| byteOffset | number | Yes| No| Offset of the buffer in the memory pool.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200013 | Cannot set property ${propertyName} of Buffer which has only a getter. |
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from("1236");
console.log(JSON.stringify(buf.length));
let arrayBuffer = buf.buffer;
console.log(JSON.stringify(new Uint8Array(arrayBuffer)));
console.log(JSON.stringify(buf.byteOffset));
```
### alloc
alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer
......@@ -40,7 +79,7 @@ Allocates and initializes a **Buffer** instance of the specified size.
| -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the **Buffer** instance to allocate, in bytes.|
| fill | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;number | No| Pre-filled value. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format (valid only when **fill** is a string). The default value is **utf-8**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format (valid only when **fill** is a string). The default value is **utf-8**.|
**Return value**
......@@ -130,7 +169,7 @@ Obtains the number of bytes of a string based on the encoding format.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| string | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;TypedArray&nbsp;\|&nbsp;DataView&nbsp;\|&nbsp;ArrayBuffer&nbsp;\|&nbsp;SharedArrayBuffer | Yes| Target string.|
| encoding | BufferEncoding | No| Encoding format. The default value is **utf-8**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format. The default value is **utf-8**.|
**Return value**
......@@ -179,8 +218,7 @@ let buf1 = buffer.from('1234');
let buf2 = buffer.from('0123');
let res = buf1.compare(buf2);
console.log(Number(res).toString());
// Print 1
console.log(Number(res).toString()); // Print 1.
```
### concat
......@@ -204,6 +242,14 @@ Concatenates an array of **Buffer** instances into a new instance of the specifi
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "totalLength" is out of range. |
**Example**
```ts
......@@ -266,6 +312,14 @@ Creates a **Buffer** instance that shares memory with the specified array of **B
| -------- | -------- |
| Buffer | **Buffer** instance with shared memory.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[byteOffset/length]" is out of range. |
**Example**
```ts
......@@ -317,8 +371,8 @@ Creates a **Buffer** instance based on the specified object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object that supports **Symbol.toPrimitive** or **valueOf()**.|
| offsetOrEncoding | number&nbsp;\|&nbsp;string | No| Byte offset or encoding format.|
| length | number | No| Length of the **Buffer** instance to create.|
| offsetOrEncoding | number&nbsp;\|&nbsp;string | Yes| Byte offset or encoding format.|
| length | number | Yes| Length of the **Buffer** instance to create.|
**Return value**
......@@ -347,7 +401,7 @@ Creates a **Buffer** instance based on a string in the given encoding format.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| string | String | Yes| String.|
| encoding | BufferEncoding | No| Encoding format of the string. The default value is **utf-8**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format of the string. The default value is **utf-8**.|
**Return value**
......@@ -491,6 +545,14 @@ Copies data at the specified position in this **Buffer** instance to the specifi
| -------- | -------- |
| number | Total length of the data copied, in bytes.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[targetStart/sourceStart/sourceEnd]" is out of range. |
**Example**
```ts
......@@ -558,7 +620,6 @@ let buf3 = buffer.from('ABCD');
console.log(buf1.equals(buf2).toString()); // Print: true
console.log(buf1.equals(buf3).toString()); // Print: false
```
### fill
......@@ -576,7 +637,7 @@ Fills this **Buffer** instance at the specified position. By default, data is fi
| value | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array&nbsp;\|&nbsp;number | Yes| Value to fill.|
| offset | number | No| Offset to the start position in this **Buffer** instance where data is filled. The default value is **0**.|
| end | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| encoding | BufferEncoding | No| Encoding format (valid only when **value** is a string). The default value is **utf-8**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format (valid only when **value** is a string). The default value is **utf-8**.|
**Return value**
......@@ -584,6 +645,14 @@ Fills this **Buffer** instance at the specified position. By default, data is fi
| -------- | -------- |
| Buffer | **Buffer** instance filled with the specified value.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/end]" is out of range. |
**Example**
```ts
......@@ -607,8 +676,8 @@ Checks whether this **Buffer** instance contains the specified value.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**. |
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
......@@ -639,8 +708,8 @@ Obtains the index of the first occurrence of the specified value in this **Buffe
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**. |
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
......@@ -696,8 +765,8 @@ Obtains the index of the last occurrence of the specified value in this **Buffer
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**. |
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
| byteOffset | number | No| Number of bytes to skip before starting to check data. If the offset is a negative number, data is checked from the end of the **Buffer** instance. The default value is **0**.|
| encoding | [BufferEncoding](#bufferencoding) | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
......@@ -736,6 +805,14 @@ Reads a signed, big-endian 64-bit Big integer from this **Buffer** instance at t
| -------- | -------- |
| bigint | A signed, big-endian 64-bit Big integer. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -744,6 +821,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigInt64BE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeBigInt64BE(0x0102030405060708n, 0);
```
### readBigInt64LE
......@@ -766,6 +846,14 @@ Reads a signed, little-endian 64-bit Big integer from this **Buffer** instance a
| -------- | -------- |
| bigint | A signed, little-endian 64-bit Big integer. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -774,6 +862,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigInt64LE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeBigInt64BE(0x0102030405060708n, 0);
```
### readBigUInt64BE
......@@ -796,6 +887,14 @@ Reads an unsigned, big-endian 64-bit Big integer from this **Buffer** instance a
| -------- | -------- |
| bigint | An unsigned, big-endian 64-bit Big integer. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -804,6 +903,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigUInt64BE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeBigUInt64BE(0xdecafafecacefaden, 0);
```
### readBigUInt64LE
......@@ -826,6 +928,14 @@ Reads an unsigned, little-endian 64-bit Big integer from this **Buffer** instanc
| -------- | -------- |
| bigint | An unsigned, little-endian 64-bit Big integer. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -834,6 +944,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigUInt64LE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeBigUInt64BE(0xdecafafecacefaden, 0);
```
### readDoubleBE
......@@ -856,6 +969,14 @@ Reads a big-endian double-precision floating-point number from this **Buffer** i
| -------- | -------- |
| number | A big-endian double-precision floating-point number. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -863,6 +984,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleBE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeDoubleBE(123.456, 0);
```
### readDoubleLE
......@@ -885,6 +1009,14 @@ Reads a little-endian double-precision floating-point number from this **Buffer*
| -------- | -------- |
| number | A little-endian double-precision floating-point number. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -892,6 +1024,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleLE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(8);
buf1.writeDoubleLE(123.456, 0);
```
### readFloatBE
......@@ -914,6 +1049,14 @@ Reads a big-endian single-precision floating-point number from this **Buffer** i
| -------- | -------- |
| number | A big-endian single-precision floating-point number. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -921,6 +1064,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readFloatBE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeFloatBE(0xcabcbcbc, 0);
```
### readFloatLE
......@@ -943,6 +1089,14 @@ Reads a little-endian single-precision floating-point number from this **Buffer*
| -------- | -------- |
| number | A little-endian single-precision floating-point number. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -950,6 +1104,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readFloatLE(0).toString());
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeFloatLE(0xcabcbcbc, 0);
```
### readInt8
......@@ -972,6 +1129,14 @@ Reads a signed 8-bit integer from this **Buffer** instance at the specified offs
| -------- | -------- |
| number | A signed 8-bit integer. |
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -980,6 +1145,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([-1, 5]);
console.log(buf.readInt8(0).toString()); // Print: -1
console.log(buf.readInt8(1).toString()); // Print: 5
let buf1 = buffer.allocUninitializedFromPool(2);
buf1.writeInt8(0x12);
```
### readInt16BE
......@@ -1002,6 +1170,14 @@ Reads a signed, big-endian 16-bit integer from this **Buffer** instance at the s
| -------- | -------- |
| number | A signed, big-endian 16-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1009,6 +1185,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0, 5]);
console.log(buf.readInt16BE(0).toString()); // Print: 5
let buf1 = buffer.alloc(2);
buf1.writeInt16BE(0x1234, 0);
```
### readInt16LE
......@@ -1031,6 +1210,14 @@ Reads a signed, little-endian 16-bit integer from this **Buffer** instance at th
| -------- | -------- |
| number | A signed, little-endian 16-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1038,6 +1225,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0, 5]);
console.log(buf.readInt16LE(0).toString()); // Print: 1280
let buf1 = buffer.alloc(2);
buf1.writeInt16BE(0x1234, 0);
```
### readInt32BE
......@@ -1060,6 +1250,14 @@ Reads a signed, big-endian 32-bit integer from this **Buffer** instance at the s
| -------- | -------- |
| number | A signed, big-endian 32-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1067,6 +1265,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0, 0, 0, 5]);
console.log(buf.readInt32BE(0).toString()); // Print: 5
let buf1 = buffer.alloc(4);
buf1.writeInt32BE(0x12345678, 0);
```
### readInt32LE
......@@ -1089,6 +1290,14 @@ Reads a signed, little-endian 32-bit integer from this **Buffer** instance at th
| -------- | -------- |
| number | A signed, little-endian 32-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1096,6 +1305,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0, 0, 0, 5]);
console.log(buf.readInt32LE(0).toString()); // Print: 83886080
let buf1 = buffer.alloc(4);
buf1.writeInt32BE(0x12345678, 0);
```
### readIntBE
......@@ -1120,6 +1332,14 @@ Reads the specified number of bytes from this **Buffer** instance at the specifi
| -------- | -------- |
| number | Data read.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -1128,6 +1348,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from("ab");
let num = buf.readIntBE(0, 1);
console.log(num.toString()); // 97
let buf1 = buffer.allocUninitializedFromPool(6);
buf1.writeIntBE(0x123456789011, 0, 6);
```
......@@ -1153,6 +1376,14 @@ Reads the specified number of bytes from this **Buffer** instance at the specifi
| -------- | -------- |
| number | Data read.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -1160,6 +1391,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readIntLE(0, 6).toString(16));
let buf1 = buffer.allocUninitializedFromPool(6);
buf1.writeIntLE(0x123456789011, 0, 6);
```
### readUInt8
......@@ -1183,6 +1417,14 @@ Reads an unsigned 8-bit integer from this **Buffer** instance at the specified o
| -------- | -------- |
| number | An unsigned 8-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1191,6 +1433,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([1, -2]);
console.log(buf.readUInt8(0).toString());
console.log(buf.readUInt8(1).toString());
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt8(0x42);
```
### readUInt16BE
......@@ -1214,6 +1459,14 @@ Reads an unsigned, big-endian 16-bit integer from this **Buffer** instance at th
| -------- | -------- |
| number | An unsigned, big-endian 16-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1222,6 +1475,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16BE(0).toString(16));
console.log(buf.readUInt16BE(1).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt16BE(0x1234, 0);
```
### readUInt16LE
......@@ -1245,6 +1501,14 @@ Reads an unsigned, little-endian 16-bit integer from this **Buffer** instance at
| -------- | -------- |
| number | An unsigned, little-endian 16-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1253,6 +1517,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16LE(0).toString(16));
console.log(buf.readUInt16LE(1).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt16LE(0x1234, 0);
```
### readUInt32BE
......@@ -1276,6 +1543,14 @@ Reads an unsigned, big-endian 32-bit integer from this **Buffer** instance at th
| -------- | -------- |
| number | An unsigned, big-endian 32-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1283,6 +1558,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32BE(0).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt32BE(0x12345678, 0);
```
### readUInt32LE
......@@ -1306,6 +1584,14 @@ Reads an unsigned, little-endian 32-bit integer from this **Buffer** instance at
| -------- | -------- |
| number | An unsigned, little-endian 32-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "offset" is out of range. |
**Example**
```ts
......@@ -1313,6 +1599,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32LE(0).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt32LE(0x12345678, 0);
```
### readUIntBE
......@@ -1337,6 +1626,14 @@ Reads the specified number of bytes from this **Buffer** instance at the specifi
| -------- | -------- |
| number | Data read.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -1344,6 +1641,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntBE(0, 6).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUIntBE(0x13141516, 0, 4);
```
### readUIntLE
......@@ -1366,7 +1666,15 @@ Reads the specified number of bytes from this **Buffer** instance at the specifi
| Type| Description|
| -------- | -------- |
| number | Data read.|
| number | A signed, big-endian 64-bit integer.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/byteLength]" is out of range. |
**Example**
......@@ -1375,6 +1683,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntLE(0, 6).toString(16));
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUIntLE(0x13141516, 0, 4);
```
### subarray
......@@ -1428,6 +1739,14 @@ Interprets this **Buffer** instance as an array of unsigned 16-bit integers and
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200009 | Buffer size must be a multiple of 16-bits |
**Example**
```ts
......@@ -1455,6 +1774,14 @@ Interprets this **Buffer** instance as an array of unsigned 32-bit integers and
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200009 | Buffer size must be a multiple of 32-bits |
**Example**
```ts
......@@ -1482,6 +1809,14 @@ Interprets this **Buffer** instance as an array of unsigned 64-bit integers and
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200009 | Buffer size must be a multiple of 64-bits |
**Example**
```ts
......@@ -1594,7 +1929,7 @@ Writes a string of the specified length to this **Buffer** instance at the speci
| str | string | Yes| String to write.|
| offset | number | No| Number of bytes to skip before starting to write data. The default value is **0**.|
| length | number | No| Maximum number of bytes to write. The default value is the length of the **Buffer** instance minus the offset.|
| encoding | BufferEncoding | No| Encoding format of the string. The default value is **utf-8**.|
| encoding | string | No| Encoding format of the string. The default value is **utf-8**.|
**Return value**
......@@ -1603,6 +1938,14 @@ Writes a string of the specified length to this **Buffer** instance at the speci
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[offset/length]" is out of range. |
**Example**
```ts
......@@ -1639,6 +1982,14 @@ Writes a signed, big-endian 64-bit Big integer to this **Buffer** instance at th
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1670,6 +2021,14 @@ Writes a signed, little-endian 64-bit Big integer to this **Buffer** instance at
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1701,6 +2060,14 @@ Writes an unsigned, big-endian 64-bit Big integer to this **Buffer** instance at
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1732,6 +2099,14 @@ Writes an unsigned, little-endian 64-bit Big integer to this **Buffer** instance
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1763,6 +2138,14 @@ Writes a big-endian double-precision floating-point number to this **Buffer** in
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1794,6 +2177,14 @@ Writes a little-endian double-precision floating-point number to this **Buffer**
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1825,6 +2216,14 @@ Writes a big-endian single-precision floating-point number to this **Buffer** in
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1857,6 +2256,14 @@ Writes a little-endian single-precision floating-point number to this **Buffer**
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1888,6 +2295,14 @@ Writes a signed 8-bit integer to this **Buffer** instance at the specified offse
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1921,6 +2336,14 @@ Writes a signed, big-endian 16-bit integer to this **Buffer** instance at the sp
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1953,6 +2376,14 @@ Writes a signed, little-endian 16-bit integer to this **Buffer** instance at the
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -1984,6 +2415,14 @@ Writes a signed, big-endian 32-bit integer to this **Buffer** instance at the sp
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2016,6 +2455,14 @@ Writes a signed, little-endian 32-bit integer to this **Buffer** instance at the
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2048,6 +2495,14 @@ Writes a big-endian signed value of the specified length to this **Buffer** inst
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -2081,6 +2536,14 @@ Writes a little-endian signed value of the specified length to this **Buffer** i
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -2112,6 +2575,14 @@ Writes an unsigned 8-bit integer to this **Buffer** instance at the specified of
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2146,6 +2617,14 @@ Writes an unsigned, big-endian 16-bit integer to this **Buffer** instance at the
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2178,6 +2657,14 @@ Writes an unsigned, little-endian 16-bit integer to this **Buffer** instance at
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2210,6 +2697,14 @@ Writes an unsigned, big-endian 32-bit integer to this **Buffer** instance at the
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2241,6 +2736,14 @@ Writes an unsigned, little-endian 32-bit integer to this **Buffer** instance at
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset]" is out of range. |
**Example**
```ts
......@@ -2273,6 +2776,14 @@ Writes an unsigned big-endian value of the specified length to this **Buffer** i
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -2305,6 +2816,14 @@ Writes an unsigned little-endian value of the specified length to this **Buffer*
| -------- | -------- |
| number | Number of bytes written.|
**Error codes**
For details about the error codes, see [Buffer Error Codes](../errorcodes/errorcode-buffer.md).
| ID| Error Message|
| -------- | -------- |
| 10200001 | The value of "[value/offset/byteLength]" is out of range. |
**Example**
```ts
......@@ -2374,7 +2893,6 @@ A constructor used to create a **Blob** instance.
**Example**
```ts
import buffer from '@ohos.buffer';
......@@ -2382,7 +2900,7 @@ let blob = new buffer.Blob(['a', 'b', 'c']);
let blob1 = new buffer.Blob(['a', 'b', 'c'], {endings:'native', type: 'MIME'});
```
### encode
### arrayBuffer
arrayBuffer(): Promise&lt;ArrayBuffer&gt;
......@@ -2396,14 +2914,14 @@ Puts the **Blob** data into an **ArrayBuffer** instance. This API uses a promise
| Promise&lt;ArrayBuffer&gt; | Promise used to return the **ArrayBuffer** containing the **Blob** data.|
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.arrayBuffer();
pro.then(val => {
let uintarr = new Uint8Array(val);
console.log(uintarr.toString());
});
```
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.arrayBuffer();
pro.then(val => {
let uintarr = new Uint8Array(val);
console.log(uintarr.toString());
});
```
### slice
slice(start?: number, end?: number, type?: string): Blob
......@@ -2426,11 +2944,11 @@ Creates a **Blob** instance by copying specified data from this **Blob** instanc
| Blob | **Blob** instance created. |
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let blob2 = blob.slice(0, 2);
let blob3 = blob.slice(0, 2, "MIME");
```
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let blob2 = blob.slice(0, 2);
let blob3 = blob.slice(0, 2, "MIME");
```
### text
......@@ -2446,10 +2964,10 @@ Returns text in UTF-8 format.
| Promise&lt;string&gt; | Promise used to return the text encoded in UTF-8.|
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.text();
pro.then(val => {
console.log(val)
});
```
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.text();
pro.then(val => {
console.log(val)
});
```
# Buffer Error Codes
## 10200001 Value Out of Range
**Error Message**
The value of ${param} is out of range.
**Description**
The value of a parameter passed in the API exceeds the valid range.
**Possible Causes**
The parameter value exceeds the value range.
**Solution**
Check and modify the parameter value.
## 10200009 Incorrect Buffer Size
**Error Message**
Buffer size must be a multiple of ${size}
**Description**
The buffer size must be an integer multiple of 16 bits, 32 bits, or 64 bits.
**Possible Causes**
The buffer size is not an integer multiple of 16 bits, 32 bits, or 64 bits.
**Solution**
Check the buffer length.
## 10200013 Read-Only Properly
**Error Message**
Cannot set property ${propertyName} of Buffer which has only a getter.
**Description**
The buffer ${propertyName} is read-only and cannot be set.
**Possible Causes**
The ${propertyName} parameter is read-only and cannot be set.
**Solution**
${propertyName} cannot be set. Do not place it on the left of the equal sign (=).
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册