Skip to content

FileBuilder

Defined in: astrobase/src/file/file-builder.ts:11

Represents a File buffer loaded into memory and contains getters & setters that parse the buffer to retrieve or set values.

T = unknown

new FileBuilder<T>(fileBuffer): FileBuilder<T>

Defined in: astrobase/src/file/file-builder.ts:15

ArrayBufferLike | ArrayLike<number>

FileBuilder<T>

buffer: Uint8Array

Defined in: astrobase/src/file/file-builder.ts:13

The raw, underlying buffer of the file.

get hasMediaType(): boolean

Defined in: astrobase/src/file/file-builder.ts:41

true if the media type is set, false otherwise. An unset (empty) media type is treated as application/octet-stream (raw bytes).

boolean


get mediaType(): Ascii

Defined in: astrobase/src/file/file-builder.ts:33

The file’s media type. An empty media type is treated as application/octet-stream (raw bytes).

Ascii


get payload(): Uint8Array

Defined in: astrobase/src/file/file-builder.ts:70

The file payload bytes.

Uint8Array


get payloadEncodingStart(): number

Defined in: astrobase/src/file/file-builder.ts:65

The position, within the buffer, of the first payload byte.

number

getValue(instance): Uint8Array<ArrayBufferLike> | Promise<T>

Defined in: astrobase/src/file/file-builder.ts:98

Get the decoded value of the file payload. If the media type is not set, this will always return the same as .payload. Otherwise, it will attempt to decode with the registered codec for the media type and return the result.

Instance

The instance to use when looking up available codecs.

Uint8Array<ArrayBufferLike> | Promise<T>

A promise that resolves with the decoded content. The type of the content is unknown, as we cannot anticipate how registered middleware will behave. You will need to assert the output type yourself.


setBuffer(fileBuffer): FileBuilder<T>

Defined in: astrobase/src/file/file-builder.ts:24

Set the raw buffer of the file.

ArrayBufferLike | ArrayLike<number>

FileBuilder<T>

This file for method chaining.


setMediaType(mediaType): FileBuilder<T>

Defined in: astrobase/src/file/file-builder.ts:52

Sets the file’s media type.

The media type string or object.

string | MediaType

FileBuilder<T>

This file for method chaining.

TypeError if the media type is invalid.


setPayload(payload): FileBuilder<T>

Defined in: astrobase/src/file/file-builder.ts:80

Sets the file’s payload.

The payload.

ArrayBufferLike | ArrayLike<number>

FileBuilder<T>

This file for method chaining.


setValue(value, instance): Promise<FileBuilder<T>>

Defined in: astrobase/src/file/file-builder.ts:115

Sets the file payload by passing a decoded value. The media type must already be set to use this method. The value will be encoded using the codec registered for the file’s media type.

T

The value to encode and use as the file payload.

Instance

The instance to use when looking up available codecs.

Promise<FileBuilder<T>>

A promise that resolves with this file for method chaining.

TypeError if no media type is set.