About JanOS

Filesystem API

The filesystem API gives low level access to the filesystem of the device. You can read, write and append to arbitrary files on the device. It's function are exposed under navigator.mozOs.

Reading a file


Promise<(DOMString or Uint8Array)> readFile(DOMString path, optional DOMString encoding = "binary");

Example:


navigator.mozOs.readFile('/data/local/user.js', 'utf-8')
  .then(content => console.log('readFile', content))
  .catch(err => console.error('readFile', err));

Writing to a file

If the file exists, the file is overwritten. If the file does not exist, it will be created.


Promise writeFile(DOMString path, (Uint8Array or DOMString) data, optional DOMString encoding = "binary");

Example:


navigator.mozOs.writeFile('/data/local/janos', 'Hello world', 'utf-8')
  .then(() => console.log('Write succeeded')
  .catch(err => console.error('Write failed', err));

Appending to a file

If the file exists, it appends the data passed into the file. If the file does not exist, it will be created.


Promise appendFile(DOMString path, (Uint8Array or DOMString) data, optional DOMString encoding = "binary");

Example:


navigator.mozOs.appendFile('/data/local/janos', '\nAnother line', 'utf-8')
  .then(() => console.log('Append succeeded')
  .catch(err => console.error('Append failed', err));

Removing a file

If the file does not exist, the promise will be rejected.


Promise removeFile(DOMString path);

Example:


navigator.mozOs.removeFile('/data/local/janos')
  .then(() => console.log('Remove succeeded')
  .catch(err => console.error('Remove failed', err));

Creating a directory


Promise createDirectory(DOMString path, optional boolean ignoreExisting = true);

Example:


navigator.mozOs.createDirectory('/data/local/logs', true)
  .then(() => console.log('CreateDirectory succeeded')
  .catch(err => console.error('CreateDirectory failed', err));