Skip to content

@fkn/lib/storage

type StorageError = Error & object;

Thrown by every member of this namespace except on an aborted signal. Match on code, never on the message.

code: StorageErrorCode;

type StoredBlob = object;

The bytes get opened, shaped like a Blob: size, stream, arrayBuffer and slice. Every read is by range and each 1 MiB record is checked before it is handed over, so a slice near the end of a large object fetches only that end.

arrayBuffer: () => Promise<ArrayBuffer>;

Promise<ArrayBuffer>

size: number;

the plaintext bytes of this blob, a slice’s own length

slice: (start?, end?) => StoredBlob;

Blob.slice’s arguments, negative ones counted from the end, and the same shape back

number

number

StoredBlob

stream: () => ReadableStream<Uint8Array>;

errors with integrity on the first record that does not open under the key

ReadableStream<Uint8Array>

function available(): Promise<boolean>;

Whether put, list and delete can run here now. get needs no account and does not depend on this. Answers rather than rejecting.

Promise<boolean>


function delete(url): Promise<void>;

Deletes an object by its url: every later get of it answers not-found, and an upload in progress is aborted and stops counting. Only the app that stored it (the same app once it is verified) deletes it, denied otherwise. An object already gone resolves.

string

Promise<void>


function get(
url,
key,
options?): Promise<StoredBlob>;

Opens an object any app stored, with no account: the broker reads its size from the first ranged answer and fetches the sealed bytes by range. Refused invalid for a url that names no stored object or a key that is not 32 bytes base64url, not-found for an object that was never made, was deleted or is still uploading (one answer for all of them). A wrong key shows on the first read, as integrity. A broker replaced while the object is held is asked to open it again on the next read.

string

string

AbortSignal

Promise<StoredBlob>


function list(options?): Promise<StoredPage>;

This app’s objects, newest first, uploads in progress included: no key, which the service never holds. limit is 1 to 1,000 (1,000 by default), and cursor is the one a previous page answered; invalid otherwise.

string

number

Promise<StoredPage>


function put(data, options?): Promise<StoredObject & object>;

Seals the data in the broker and uploads it, then answers its url and the key that opens it: the app’s own key unchanged, or the one the broker minted. Resolves once the object is ready. Needs a signed-in account, and counts the sealed size (28 bytes more per 1 MiB) against the account’s storage from the moment it starts until the object is deleted or the upload is aborted. The account the call belongs to is the one this page is on when it is made, as for every storage call.

data is a Blob (a File included) or a ReadableStream<Uint8Array> with its size. An upload survives the network dropping a part, not a reload: a reload starts the file again, and the upload left behind stops counting within the hour.

Refused invalid for a stream without its size or one that delivers another, a file past the service’s part ceiling, or a key that is not 32 bytes base64url; denied with no account; quota; too-many past the account’s stored objects or this hour’s uploads; account-changed.

Blob | ReadableStream<Uint8Array<ArrayBufferLike>>

StoragePutOptions = {}

Promise<StoredObject & object>

Re-exports StorageErrorCode


Re-exports StorageProgress


Re-exports StoragePutOptions


Re-exports StoredObject


Re-exports StoredPage