Skip to main content
Version: v2

readSync

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Synchronously reads the content from the file specified by the file handle into the given ArrayBuffer..

Type

function readSync(option: Option): Result

Parameters

Option

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

Options

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
offsetnumberN0The position in buffer to write the data to2.0
lengthnumberNbuffer.byteLengthThe number of bytes to read, the default is the number of bytes passed into the buffer2.0
positionnumber|nullNnullSpecifies the position from which to start reading from the file. If position is null, the data will be read from the current file position and the file position will be updated2.0

Result

TypeDescription
numberThe number of bytes read

Example

import { openSync, readSync, O_RDONLY } from '@zos/fs'

const fd = openSync({
path: 'test.txt',
flag: O_RDONLY,
})

const buffer = new ArrayBuffer(4)
const result = readSync({
fd,
buffer,
})

if (result === 0) {
console.log('readSync success')
}