writeSync
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Synchronously write ArrayBuffer to the file specified by fd.
Type
function writeSync(option: Option): Result
Parameters
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
fd | number | Y | - | File handle, returned by the openSync , openAssetsSync and other APIs | 2.0 |
buffer | ArrayBuffer | Y | - | The buffer that the data will be written to | 2.0 |
options | Options | N | - | Other Options | 2.0 |
Options
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
offset | number | N | 0 | Based on first address offset in ArrayBuffer to write the data | 2.0 |
length | number | N | buffer.byteLength | The number of bytes to write, the default is the length of the incoming buffer | 2.0 |
position | number|null | N | null | Position refers to the offset from the beginning of the file where this data should be written. If position is 'null', the data will be written at the and the file position will be updated | 2.0 |
Result
Type | Description |
---|---|
number | The number of bytes written |
Example
import { openSync, writeSync, O_RDWR, O_CREAT } from '@zos/fs'
const fd = openSync({
path: 'test.txt',
flag: O_RDWR | O_CREAT,
})
const buffer = new ArrayBuffer(4)
const result = writeSync({
fd,
buffer,
})
if (result === 0) {
console.log('writeSync success')
}