notesy::files

A folder of the plugin's own, for what it keeps that isn't a setting or a small value (those go in the store): caches, downloads, exports it builds up. It's all of the disk a script can reach. Needs no permission.

rustuse notesy::{files, json, log};

pub fn ready() {
    files::write("cache/today.json", json::text(#{ count: 3 }));
    files::append("history.txt", "opened\n");
    if let Some(text) = files::read("cache/today.json") {
        let today = json::parse(text)?;
        log::info(`${today.count} from the cache`);
    }
    for entry in files::list("") {
        log::info(`${entry.name}: ${entry.size} bytes`);
    }
}
Function What it does
files::read(path) A file's text, Some(text), or None when there's no such file. A file that isn't text is an error: read it with read_bytes.
files::read_bytes(path) A file's bytes, Some(bytes), or None.
files::write(path, data) Writes the file (text or bytes), replacing what was there, and makes the folders it's in.
files::append(path, data) Adds to the file's end, making it when it isn't there.
files::list(folder) What's in a folder ("" for the top), folders first: #{ name, folder, size }.
files::exists(path) Whether there's a file or folder there.
files::remove(path) Deletes a file, or a folder and everything in it.
files::rename(from, to) Moves a file or folder; to mustn't be there already.
files::open(path) Opens one of its files in a tab of its own, in front, for the user to read and edit; what they write is saved back to it. Only a note's kind of file (.md, .markdown, .txt), and it takes ui. Such a tab isn't a note in the vault: no history, tags, search or note events.
files::usage() What its files take up: #{ bytes, entries, max_bytes, max_entries }.

#Paths

Relative to the plugin's folder, with / between parts: cache/today.json. A path that could mean anything else is an error, not read another way: one starting with /, with .. or ., a \, a :, a control character, a name ending in a dot or a space, or one Windows keeps for a device (con, nul, com1). At most 16 folders deep.

Nothing in the folder may be a link: a path that goes through one is an error, and list leaves them out. A script can't make one.

#Room

At most 100 MB and 10,000 files and folders together, and 20 MB for one file. A write that would go past that is an error, and nothing is written.

#Where it is

plugin-data/<plugin id>/files in notesy's config folder, beside its store. Removing the plugin with its data deletes it.

Every page