readonly number[] import {CHUNK_UPLOAD_RETRY_DELAYS} from '@fuzdev/zzz/chunk_upload.js'; Waits between attempts of one chunk; a chunk fails once these run out.
Uploads a file as a sequence of chunks through the backend's byte routes, one at a time and in order, as they're produced.
3 declarations
readonly number[] import {CHUNK_UPLOAD_RETRY_DELAYS} from '@fuzdev/zzz/chunk_upload.js'; Waits between attempts of one chunk; a chunk fails once these run out.
import {ChunkUpload} from '@fuzdev/zzz/chunk_upload.js'; One file's upload. create makes the file, enqueue appends each chunk
after the ones before it, and flush waits for everything queued.
Each chunk is appended at the offset the upload expects, so one can never land twice or out of order. A request that gets no answer or a server error is retried; when the retry finds the file already grew by exactly this chunk, the earlier attempt landed and the chunk is done. Any other refusal — the file changed underneath, the session ended — fails the upload.
pathtype string
uploaded_bytesThe file's size as the backend last confirmed it.
type number
errorWhy the upload failed, once it has.
type string | null
constructortype new (options: ChunkUploadOptions): ChunkUpload
optionscreateCreates the file, empty. Call it once, before any enqueue.
type (): Promise<void>
Promise<void>throws
Error - when the file can't be created — `already exists` for a taken pathenqueueQueues a chunk to append after every chunk queued before it. Chunks queued after the upload failed are dropped.
type (chunk: Blob): void
chunkBlobvoidflushWaits for every queued chunk.
type (): Promise<void>
Promise<void>throws
Error - with the failure when the upload failedChunkUploadOptions import type {ChunkUploadOptions} from '@fuzdev/zzz/chunk_upload.js'; fetchtype (input: string, init?: RequestInit | undefined): Promise<Response>
inputstringinit?RequestInitPromise<Response>api_urlThe API's URL or path, with no trailing slash.
type string
pathThe absolute path of the file to create and append to.
type string
on_progress?Called with the file's size each time a chunk lands.
type (uploaded_bytes: number): void
uploaded_bytesnumbervoidon_error?Called once, when a chunk fails for good. Nothing is uploaded after.
type (message: string): void
messagestringvoidretry_delays?Waits between attempts of one chunk (default CHUNK_UPLOAD_RETRY_DELAYS).
type readonly number[]
sleep?Waits ms (default wait).
type (ms: number): Promise<unknown>
msnumberPromise<unknown>