Skip to main content

File System

https://emscripten.org/docs/api_reference/Filesystem-API.html#id2

For Example

import { init, fs } from 'pcl.js';await init();fs.writeFile('file', 'foobar');

Methods

writeFile

writeFile(path, data, options);

Writes the entire contents of data to the file at path. For example:

fs.writeFile('file', 'foobar');

readFile

fs.readFile(path, options);

Reads the entire file at path and returns it as a string (encoding is utf8), or as a new Uint8Array buffer (encoding is binary).

Returns:

TypeDescription
string or ArrayBufferThe contents of the file..
fs.unlink(path);

This removes a name from the file system. If that name was the last link to a file (and no processes have the file open) the file is deleted.

rename

fs.rename(oldPath, newPath);

Renames the node at oldpath to newpath.

mkdir

fs.mkdir(path, mode);

Creates a new directory node in the file system.

rmdir

fs.rmdir(path);

Removes an empty directory located at path.

readdir

fs.readdir(path);

Reads the entire files at path and returns it as a array. For example:

const result = fs.readdir('/)console.log(result) // ['dev', 'temp']