Filesystem

Filesystem: Reading, Writing and Directories

Filesystem reads and writes paths relative to a Directory: Data (the app's private files/), Cache, Documents, Library (iOS) and the shared External locations on Android. BookNest keeps a note per book:

Writing, appending and listing notes in src/js/lab.jsJavaScript
const NOTE = { path: 'notes/book-1.txt', directory: Directory.Data, encoding: Encoding.UTF8 };
export async function notes() {
  await Filesystem.writeFile({ ...NOTE, data: 'Reread chapter 3.\n', recursive: true });
  await Filesystem.appendFile({ ...NOTE, data: 'Lend to Sam on Friday.\n' });
  const { data } = await Filesystem.readFile(NOTE);
  const { files } = await Filesystem.readdir({ path: 'notes', directory: Directory.Data });
  const { uri } = await Filesystem.getUri(NOTE);
  return show('notes', { data, files: files.map((f) => `${f.name} (${f.size} bytes)`), uri });
}
Output
LAB notes {"data":"Reread chapter 3.\nLend to Sam on Friday.\n","files":["book-1.txt (41
  bytes)"],"uri":"file:///data/user/0/com.example.booknest/files/notes/book-1.txt"}

recursive: true created the notes folder. Omit encoding and data is base64 both ways, which is how binary files cross the JSON bridge (Serializing Across the Bridge); for large downloads and uploads, the File Transfer plugin moves the bytes natively. App directories need no permission; storage permissions matter only for Documents and ExternalStorage on Android 10 and older. In a browser the plugin stores files in IndexedDB.