gizweb:files
An app's stored files. The bytes are a file in the app's folder, named by their SHA-256, so one content is kept once; a record holds the owner, type and size. Their bytes together stay under the app's quota (counters.giz). A record is written only after its bytes, so a record never lacks them.
import * as Files from "gizweb:files";Types
Stored
type Stored = { @Key id: string; @Index("owner") owner: string; type: string; size: i64; @Index("digest") digest: string; }One stored file: who owns it, its media type, size and the SHA-256 of its bytes (hex).
id:stringowner:stringtype:stringsize:i64digest:string
Files
type Files = { sys: System; db: Data.Db; folder: string; }Where the files are: the records in DB and the bytes in FOLDER.
sys:gizlang_system.Systemdb:M73.Dbfolder:string
Functions
install
function install(d: Data.Db): bool throws Model.RejectionMakes the files table when it is not there.
Effects: fail, read, write, console, io.
put
function put(files: Files, id: string, owner: string, type: string, content: bytes, quota: i64): Stored throws Model.RejectionStores CONTENT as file ID of OWNER with media TYPE, when all files stay within QUOTA bytes; a 429 otherwise.
Effects: fail, read, write, console, io.
find
function find(files: Files, id: string): Option<Stored> throws Model.RejectionThe record of file ID.
Effects: fail, read, write, console, io.
read
function read(files: Files, stored: Stored): bytes throws Model.RejectionThe bytes of STORED, checked against its digest.
Effects: fail, io.
remove
function remove(files: Files, id: string, owner: string): bool throws Model.RejectionRemoves file ID of OWNER; false when OWNER has no such file.
Effects: fail, read, write, console, io.