@fkn/lib/storage
Type Aliases
Section titled “Type Aliases”StorageError
Section titled “StorageError”type StorageError = Error & object;Thrown by every member of this namespace except on an aborted signal. Match on code, never on the message.
Type Declaration
Section titled “Type Declaration”code: StorageErrorCode;StoredBlob
Section titled “StoredBlob”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.
Properties
Section titled “Properties”arrayBuffer
Section titled “arrayBuffer”arrayBuffer: () => Promise<ArrayBuffer>;Returns
Section titled “Returns”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
Parameters
Section titled “Parameters”start?
Section titled “start?”number
number
Returns
Section titled “Returns”stream
Section titled “stream”stream: () => ReadableStream<Uint8Array>;errors with integrity on the first record that does not open under the key
Returns
Section titled “Returns”ReadableStream<Uint8Array>
Functions
Section titled “Functions”available()
Section titled “available()”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.
Returns
Section titled “Returns”Promise<boolean>
delete()
Section titled “delete()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”string
string
options?
Section titled “options?”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”list()
Section titled “list()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”cursor?
Section titled “cursor?”string
limit?
Section titled “limit?”number
Returns
Section titled “Returns”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.
Parameters
Section titled “Parameters”Blob | ReadableStream<Uint8Array<ArrayBufferLike>>
options?
Section titled “options?”StoragePutOptions = {}
Returns
Section titled “Returns”Promise<StoredObject & object>
References
Section titled “References”StorageErrorCode
Section titled “StorageErrorCode”Re-exports StorageErrorCode
StorageProgress
Section titled “StorageProgress”Re-exports StorageProgress
StoragePutOptions
Section titled “StoragePutOptions”Re-exports StoragePutOptions
StoredObject
Section titled “StoredObject”Re-exports StoredObject
StoredPage
Section titled “StoredPage”Re-exports StoredPage