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.
Type Parameters
Section titled “Type Parameters”T
= unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileBuilder<
T
>(fileBuffer
):FileBuilder
<T
>
Defined in: astrobase/src/file/file-builder.ts:15
Parameters
Section titled “Parameters”fileBuffer
Section titled “fileBuffer”ArrayBufferLike
| ArrayLike
<number
>
Returns
Section titled “Returns”FileBuilder
<T
>
Properties
Section titled “Properties”buffer
Section titled “buffer”buffer:
Uint8Array
Defined in: astrobase/src/file/file-builder.ts:13
The raw, underlying buffer of the file.
Accessors
Section titled “Accessors”hasMediaType
Section titled “hasMediaType”Get Signature
Section titled “Get Signature”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).
Returns
Section titled “Returns”boolean
mediaType
Section titled “mediaType”Get Signature
Section titled “Get Signature”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).
Returns
Section titled “Returns”payload
Section titled “payload”Get Signature
Section titled “Get Signature”get payload():
Uint8Array
Defined in: astrobase/src/file/file-builder.ts:70
The file payload bytes.
Returns
Section titled “Returns”Uint8Array
payloadEncodingStart
Section titled “payloadEncodingStart”Get Signature
Section titled “Get Signature”get payloadEncodingStart():
number
Defined in: astrobase/src/file/file-builder.ts:65
The position, within the buffer, of the first payload byte.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”getValue()
Section titled “getValue()”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.
Parameters
Section titled “Parameters”instance
Section titled “instance”The instance to use when looking up available codecs.
Returns
Section titled “Returns”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()
Section titled “setBuffer()”setBuffer(
fileBuffer
):FileBuilder
<T
>
Defined in: astrobase/src/file/file-builder.ts:24
Set the raw buffer of the file.
Parameters
Section titled “Parameters”fileBuffer
Section titled “fileBuffer”ArrayBufferLike
| ArrayLike
<number
>
Returns
Section titled “Returns”FileBuilder
<T
>
This file for method chaining.
setMediaType()
Section titled “setMediaType()”setMediaType(
mediaType
):FileBuilder
<T
>
Defined in: astrobase/src/file/file-builder.ts:52
Sets the file’s media type.
Parameters
Section titled “Parameters”mediaType
Section titled “mediaType”The media type string or object.
string
| MediaType
Returns
Section titled “Returns”FileBuilder
<T
>
This file for method chaining.
Throws
Section titled “Throws”TypeError
if the media type is invalid.
setPayload()
Section titled “setPayload()”setPayload(
payload
):FileBuilder
<T
>
Defined in: astrobase/src/file/file-builder.ts:80
Sets the file’s payload.
Parameters
Section titled “Parameters”payload
Section titled “payload”The payload.
ArrayBufferLike
| ArrayLike
<number
>
Returns
Section titled “Returns”FileBuilder
<T
>
This file for method chaining.
setValue()
Section titled “setValue()”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.
Parameters
Section titled “Parameters”T
The value to encode and use as the file payload.
instance
Section titled “instance”The instance to use when looking up available codecs.
Returns
Section titled “Returns”Promise
<FileBuilder
<T
>>
A promise that resolves with this file for method chaining.
Throws
Section titled “Throws”TypeError
if no media type is set.