⚠️

此页需要翻译

File system

The fs module enables interacting with the file system in a way modeled on standard POSIX functions.

Repo

Install

To keep the core program simplified, the FS module is not included by the runtime, so you have to install it from npm.

npm install --save lichenscript-fs

Usage

Read/Write data into buffer

Read data from file:

import fs from "lichenscript-fs";
function main() {
const content = fs.readFileContent("/tmp/foo.txt").unwrap();
print(content);
}

Write data to file:

import fs from "lichenscript-fs";
function main() {
fs.writeFileContent("foo.txt", "Hello World").unwrap();
}

Read/Write data into buffer

import fs from "lichenscript-fs";
function main() {
// Read data into buffer from file:
const buffer = fs.readFile("/tmp/foo.txt").unwrap();
print(content);
// Write buffer to file:
fs.writeFile("foo.txt", buffer).unwrap();
}

Unlink a file:

import fs from "lichenscript-fs";
function main() {
fs.unlink("foo.txt").unwrap();
}