Skip to content
API reference

files

Import
import * as api from "@fungi.computer/oyster/files";
Kind Export Description
type alias FileEntry One entry of a directory listing, in Agar’s computer.list contract.
type alias FileListing A page of a directory, in Agar’s computer.list contract.
type alias FileReplaceOutcome What a conditional replace did, in Agar’s computer.writeFile contract.
type alias FileSource Where an Oyster’s files live. Paths are absolute (/notes/a.md) and already normalized by the routes; a source never sees ...
function normalizeFilePath() Normalize an absolute path; null when it is not one or escapes the root.
function fileCapabilities() File capabilities sharing the existing /files/ wire and one file source.

FileEntrytype alias

Section titled “FileEntry”
Signature
type FileEntry = Readonly<{
name: string;
type: "file" | "directory" | "symlink";
size: number;
modifiedAt: number;
}>;

One entry of a directory listing, in Agar’s computer.list contract.


FileListingtype alias

Section titled “FileListing”
Signature
type FileListing = Readonly<{
path: string;
entries: readonly FileEntry[];
nextOffset: number | null;
}>;

A page of a directory, in Agar’s computer.list contract.


FileReplaceOutcometype alias

Section titled “FileReplaceOutcome”
Signature
type FileReplaceOutcome =
| Readonly<{
kind: "replaced";
path: string;
bytes: number;
}>
| Readonly<{
kind: "conflict";
}>;

What a conditional replace did, in Agar’s computer.writeFile contract.


FileSourcetype alias

Section titled “FileSource”
Signature
type FileSource = Readonly<{
list: Promise<Readonly<{
path: string;
entries: readonly FileEntry[];
nextOffset: number | null;
}> | null>;
read: Promise<Uint8Array<ArrayBufferLike> | null>;
write: Promise<void>;
mkdir: Promise<void>;
replace: Promise<FileReplaceOutcome>;
}>;

Where an Oyster’s files live. Paths are absolute (/notes/a.md) and already normalized by the routes; a source never sees ...

normalizeFilePath()function

Section titled “normalizeFilePath()”
Signature
function normalizeFilePath(raw): string | null;

Normalize an absolute path; null when it is not one or escapes the root.

Parameter Type
raw string

string | null


fileCapabilities()function

Section titled “fileCapabilities()”
Signature
function fileCapabilities(source): readonly Readonly<object & object>[];

File capabilities sharing the existing /files/ wire and one file source.

Parameter Type
source FileSource

readonly Readonly<object & object>[]