> 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
importbufferfrom'@ohos.buffer';
```
## BufferEncoding
Enumerates the supported encoding formats of strings.
@@ -576,7 +637,7 @@ Fills this **Buffer** instance at the specified position. By default, data is fi
| value | string \| Buffer \| Uint8Array \| 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 \| number \| Buffer \| 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 \| number \| Buffer \| 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 \| number \| Buffer \| 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';