Skip to main content

Crate day_part_filesystem

Crate day_part_filesystem 

Source
Expand description

day-part-filesystem: app-local file storage with one API on every target (docs/fs.md). No UI; any Rust code can depend on this crate and call read/write()/list/remove.

day_part_filesystem::write("notes/today.txt", b"rain later")?;
let bytes = day_part_filesystem::read("notes/today.txt")?;

Files live under a private per-app root: a real directory on the native targets (the mobile hosts pass it as DAY_DATA_DIR; desktops use the platform’s data-dir convention), and the browser’s Origin Private File System on web-dom. Paths are relative and sandboxed (an absolute path or a ./.. segment is FsError::BadPath), and write creates missing parent directories.

Threading. The blocking calls run where you call them, so keep them off the UI thread for large files; on web they return FsError::Unsupported (one thread, no blocking waits: the day-part-http rule). The *_async twins and futures work on every target; completions arrive on an unspecified background thread natively and on the sole browser thread on web, so deliver into UI state with a Setter or await under day::task (docs/async.md).

Structs§

FsFuture
An in-flight storage operation; .await resolves it.

Enums§

FsError
A storage failure. The web tier collapses provider detail into FsError::Io, like day-part-http’s error taxonomy does for the browser.

Functions§

data_dir
The app’s data directory on native targets, day_process::storage::data_dir: DAY_DATA_DIR when a host or a test sets it, else the platform’s folder for this app (Application Support on Apple platforms, %LOCALAPPDATA% on Windows, $XDG_DATA_HOME on Linux, each followed by the app id). This part’s own files live in its day-fs/ subdirectory; other parts that keep files, such as a download manager’s journal, take a sibling. The web has no such directory.
list
List the entry names directly under dir ("" = the storage root), sorted. Directories are listed with a trailing /. Blocking; FsError::Unsupported on web.
list_async
list without blocking.
list_future
list_async as a Future.
open_read
Open an app-local file for read-only, seekable access on native targets. Uses the same relative path rules and storage root as read. This lets archive readers fetch individual entries without loading the whole file. Opening and reading are blocking; use a worker when called from UI code. Not available on web, whose storage API currently supplies owned buffers through read_future.
platform_data_dir
The platform’s shared application-data directory, the one other applications keep their own folders in: ~/Library/Application Support on Apple, the roaming %APPDATA% on Windows (where Electron and Tauri apps keep theirs), $XDG_DATA_HOME (else ~/.local/share) elsewhere. For an app that opens a store another application keeps there, the way a CLI companion of a desktop app reads that app’s database. DAY_DATA_DIR does not redirect it: a host that names the app’s own directory says nothing about where other applications keep theirs.
read
Read a file’s bytes. Blocking; FsError::Unsupported on web, so use read_async or read_future there (they work everywhere).
read_async
read without blocking; on_done runs on an unspecified background thread (the sole browser thread on web).
read_future
read_async as a Future.
remove
Remove a file (or an empty directory). Blocking; FsError::Unsupported on web. Removing a missing path is FsError::NotFound.
remove_async
remove without blocking.
remove_future
remove_async as a Future.
write
Write bytes to path (create or truncate), creating missing parent directories. Blocking; FsError::Unsupported on web.
write_async
write() without blocking.
write_future
write_async as a Future.