Skip to main content
Version: v3

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

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
fdnumberY-File handle, returned by the openSync, openAssetsSync and other APIs2.0
bufferArrayBufferY-The buffer that the data will be written to2.0
optionsOptionsN-Other Options2.0

Options

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
offsetnumberN0Based on first address offset in ArrayBuffer to write the data2.0
lengthnumberNbuffer.byteLengthThe number of bytes to write, the default is the length of the incoming buffer2.0
positionnumber|nullNnullPosition 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 updated2.0

Result

TypeDescription
numberThe 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,
})