file_bytes.ts

The backend's byte routes for files: read a file's bytes (with Range), create a file from bytes, and append bytes at an expected offset. Plain HTTP beside the JSON-RPC endpoint, for content that isn't text or doesn't fit one message.

view source

Declarations
#

10 declarations

append_file_bytes
#

file_bytes.ts view source

(fetch: FileBytesFetch, api_url: string, path: string, offset: number, body: Blob | BufferSource): Promise<FileBytesWriteResult> import {append_file_bytes} from '@fuzdev/zzz/file_bytes.js';

Appends bytes to a file, only if it is exactly offset bytes long. Otherwise it fails with offset_mismatch and the file's current size, having written nothing.

fetch

the fetch to send with

api_url

the API's URL or path, with no trailing slash

type string

path

the file's absolute path

type string

offset

the size the file must currently have

type number

body

the bytes to append

type Blob | BufferSource

returns

Promise<FileBytesWriteResult>

create_file_bytes
#

file_bytes.ts view source

(fetch: FileBytesFetch, api_url: string, path: string, body?: Blob | BufferSource | null): Promise<FileBytesWriteResult> import {create_file_bytes} from '@fuzdev/zzz/file_bytes.js';

Creates a file from bytes, never replacing one: a taken path fails with already_exists.

fetch

the fetch to send with

api_url

the API's URL or path, with no trailing slash

type string

path

the new file's absolute path

type string

body

the file's first bytes, or null to create it empty

type Blob | BufferSource | null
default null

returns

Promise<FileBytesWriteResult>

FILE_BYTES_MAX_BODY_BYTES
#

file_bytes.ts view source

number import {FILE_BYTES_MAX_BODY_BYTES} from '@fuzdev/zzz/file_bytes.js';

Largest body one create or append accepts, in bytes — twin of the backend's FILE_BYTES_MAX_BODY_BYTES. A larger file is written as several appends.

FILE_BYTES_SUBPATH
#

file_bytes.ts view source

"/files/bytes" import {FILE_BYTES_SUBPATH} from '@fuzdev/zzz/file_bytes.js';

The byte routes' path below the API path — twin of the backend's FILE_BYTES_PATH, which the cross-backend byte-route suite pins it to.

FileBytesError
#

file_bytes.ts view source

FileBytesError import type {FileBytesError} from '@fuzdev/zzz/file_bytes.js';

Body of a refused request. error is a reason like already_exists, offset_mismatch, path_not_allowed, or authentication_required.

error

type string

size?

The file's current size, sent with offset_mismatch.

type number

FileBytesFetch
#

file_bytes.ts view source

FileBytesFetch import type {FileBytesFetch} from '@fuzdev/zzz/file_bytes.js';

The fetch the byte-route calls go through.

(call)

type (input: string, init?: RequestInit | undefined): Promise<Response>

input

type string

init?

type RequestInit
optional
returns Promise<Response>

FileBytesWriteResult
#

file_bytes.ts view source

FileBytesWriteResult

type { ok: true; size: number; } | { ok: false; status: number; reason: string; size?: number | undefined; }

import type {FileBytesWriteResult} from '@fuzdev/zzz/file_bytes.js';

Outcome of a create or an append. On failure status is the HTTP status (0 when the request never got an answer) and reason the backend's error (network_error or invalid_response when there was none).

FileBytesWritten
#

file_bytes.ts view source

FileBytesWritten import type {FileBytesWritten} from '@fuzdev/zzz/file_bytes.js';

Body of a successful create (201) or append (200): the file's size after it.

size

type number

to_file_bytes_append_url
#

file_bytes.ts view source

(api_url: string, path: string, offset: number): string import {to_file_bytes_append_url} from '@fuzdev/zzz/file_bytes.js';

Builds the URL to PATCH to append to a file. The append lands only if the file is exactly offset bytes long.

api_url

the API's URL or path, with no trailing slash

type string

path

the file's absolute path

type string

offset

the size the file must currently have

type number

returns

string

to_file_bytes_url
#

file_bytes.ts view source

(api_url: string, path: string): string import {to_file_bytes_url} from '@fuzdev/zzz/file_bytes.js';

Builds the URL of a file's bytes. GET it to read (a media element can use it as its src), POST to create the file from the request body.

api_url

the API's URL or path, with no trailing slash

type string

path

the file's absolute path

type string

returns

string

Imported by
#