FileSystemManager.readFile

Requires:
BaseKit≥2.0.1
Platforms:
iOSAndroid

Method signature
FileSystemManager.readFile(params: )

Description

Read the contents of a local file

Parameters

PropertyTypeRequiredDefaultDescription
filePathstringYes-File path to read (local path)
encodingstringNo"utf8"Specify the character encoding for reading the file. Supports utf8/ascii/base64. If encoding is not provided, defaults to utf8.
positionnumberNo-Read starting from the specified position in the file; if not specified, start from the beginning. The read range is [position, position+length) (left-closed, right-open). Valid range: [0, fileLength - 1]. Unit: byte
lengthnumberNo-Specify the length to read; if not specified, read to the end of the file. Valid range: [1, fileLength]. Unit: byte
complete() => voidNo-Completion callback (executed on both success and failure)
success(params: Object) => voidNo-Callback on successful API call
fail(params: Object) => voidNo-Failure callback
success callback parameters
PropertyTypeDescriptionSince
datastringFile contentv3.2.6
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { getFileSystemManager } from '@ray-js/ray'

// Write a file first to ensure there is something to read.
const fm = await getFileSystemManager();

fm.writeFile({
  filePath: "thingfile://usr/ttt_demo.txt",
  data: "hello ttt",
  success: () => {
    fm.readFile({
      filePath: "thingfile://usr/ttt_demo.txt",
      encoding: "utf8",
      success: data => {
        console.log(data);
      },
      fail: error => {
        console.error(error);
      },
    });
  },
  fail: error => {
    console.error(error);
  },
});