fileSystem
Use fileSystem for documents, cached downloads and media files in the app sandbox. Use storage or db for structured app state.
Write a note and download a photo
import { Image, fileSystem } from 'kuito';
const url = 'https://example.com/photo.jpg';
const notes = fileSystem.documents + 'notes.txt';
await fileSystem.write(notes, 'hello');
await fileSystem.write(notes, ' world', { append: true });
await fileSystem.read(notes); // 'hello world'
await fileSystem.readBytes(notes, { position: 6, length: 5 }); // an ArrayBuffer of 'world'
await fileSystem.info(notes); // { exists: true, uri, isDirectory: false, size: 11, lastModified }
await fileSystem.delete(notes);
const photo = fileSystem.download(url, fileSystem.cache + 'photo.jpg', {
headers: { Authorization: 'Bearer …' },
onProgress: ({ bytes, total }) => console.log(bytes, total),
});
const { uri } = await photo; // or photo.cancel()
export const Photo = () => <Image src={{ uri }} />;Behavior and limits
documents persists until the app or user removes its data; cache can be evicted; bundle is read-only. Directory URIs end in /. Android bundled files use asset:/// rather than an on-disk path. Create parent directories before writing. Transfers return cancellable promises and stream between disk and the network. A download rejects outside HTTP 200–299 and replaces its target only after success; an upload returns the response status for you to check. Handle missing files, sandbox violations, network errors and cancellation. Downloads do not continue as background OS transfers.
Continue
Read Storage for the related workflow. The API reference lists every method, option, event and return type.
Referenz
Exporte 24
Methoden, Konstanten und Typen, die dieser native Namespace bereitstellt.
readThe file as UTF-8 text; ERR_ENCODING when it isn't.functionreadBytesThe file's bytes, or length of them from position.functionwriteText as UTF-8, or an ArrayBuffer's bytes as they are.functioninfoWhat is at a file:// URI, if anything: whether it is a directory, its size and when it last changed.functionexistsWhether anything, a file or a directory, is at a file:// URI.functioncreateDirectoryFails if the parent is missing, unless intermediates creates it.functionmoveReplaces whatever is at to.functioncopyCopies a file or a directory; replaces whatever is at to.functionlistThe names of the directory's entries.functiondownloadStreams url into the file at to, replacing it once the whole body has
arrived.functionuploadStreams the file at from to url, and resolves with the response whatever its status.typeFileInfoWhat info finds at a URI.typeByteRangePicks the part of a file fileSystem.readBytes reads, for reading a header or a large file in pieces.typeWriteOptionsSays whether fileSystem.write() replaces the file or adds to its end.typeTransferProgressHow far a transfer is.typeFileTransferA running download or upload: await it, or cancel it to reject with ERR_CANCELED.typeDownloadOptionsAdds request headers to a download and follows its progress.typeDownloadResultWhere a finished download is on disk and what the server answered.typeUploadOptionsSays how a file is uploaded: the HTTP method and headers, as the whole body or a form field, and its progress.typeUploadResultWhat the server answered to an upload.valuedocumentsKept until the app deletes it; backed up on iOS.valuecacheThe system may clear it when space runs low.valuebundleThe app's own files, read-only: the iOS bundle, asset:/// on Android.functiondeleteDeletes a file or a directory with its contents.