Skip to main content
Defined in: packages/common/src/common/file.ts:20 Represents a file asset that has been registered with the engine.

Remarks

Instances are returned by AssetContext.getAsset. Each method lazily fetches the file from the engine’s virtual file system and returns the content in the requested format. All read methods throw NfFetchException when the underlying fetch returns a non-OK response.

Example

Constructors

Constructor

new NfFile(path): NfFile
Defined in: packages/common/src/common/file.ts:26

Parameters

path
string Internal URL path used to fetch the file.

Returns

NfFile

Accessors

path

Get Signature

get path(): string
Defined in: packages/common/src/common/file.ts:33 Internal URL path used to fetch the file.
Returns
string

Methods

arrayBuffer()

arrayBuffer(): Promise<ArrayBuffer>
Defined in: packages/common/src/common/file.ts:42 Fetch the file and return its content as an ArrayBuffer.

Returns

Promise<ArrayBuffer>

Throws

NfFetchException When the HTTP response is not OK.

blob()

blob(): Promise<Blob>
Defined in: packages/common/src/common/file.ts:52 Fetch the file and return its content as a Blob.

Returns

Promise<Blob>

Throws

NfFetchException When the HTTP response is not OK.

bytes()

bytes(): Promise<Uint8Array<ArrayBuffer>>
Defined in: packages/common/src/common/file.ts:62 Fetch the file and return its content as a Uint8Array.

Returns

Promise<Uint8Array<ArrayBuffer>>

Throws

NfFetchException When the HTTP response is not OK.

formData()

formData(): Promise<FormData>
Defined in: packages/common/src/common/file.ts:72 Fetch the file and return its content as FormData.

Returns

Promise<FormData>

Throws

NfFetchException When the HTTP response is not OK.

json()

json(): Promise<any>
Defined in: packages/common/src/common/file.ts:82 Fetch the file, parse it as JSON, and return the result.

Returns

Promise<any>

Throws

NfFetchException When the HTTP response is not OK.

text()

text(): Promise<string>
Defined in: packages/common/src/common/file.ts:92 Fetch the file and return its content as a UTF-8 string.

Returns

Promise<string>

Throws

NfFetchException When the HTTP response is not OK.