Skip to content

OcflFile

Defined in: src/ocfl-file.ts:17

A file in one version of an OCFL object.

readonly createdAt: Date

Defined in: src/ocfl-file.ts:33

When OcflFile.createdIn was committed. From the inventory, never from the stored file, whose times change when it is copied or restored.


readonly createdIn: Version

Defined in: src/ocfl-file.ts:26

The version in which this logical path was created: the first of the versions up to this file’s own that all have it, with any content. A logical path removed and later added again is created again, and a rename creates the new logical path.


readonly digest: string

Defined in: src/ocfl-file.ts:21

Lowercase hex digest of the content, in the object’s OcflObject.digestAlgorithm.


readonly modifiedAt: Date

Defined in: src/ocfl-file.ts:35

When OcflFile.modifiedIn was committed, such as for an HTTP Last-Modified header. From the inventory, never from the stored file.


readonly modifiedIn: Version

Defined in: src/ocfl-file.ts:31

The version in which this logical path took its current content: the first of the versions up to this file’s own that all have it with this digest. Content changed and later changed back is modified again.


readonly path: string

Defined in: src/ocfl-file.ts:19

Logical path within the version, such as audio/1.wav.

bytes(): Promise<Uint8Array<ArrayBuffer>>

Defined in: src/ocfl-file.ts:88

Reads the content into memory.

Promise<Uint8Array<ArrayBuffer>>

OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.

The file system error if the stored file is missing or can’t be read.

const checksum = createHash('md5').update(await file.bytes()).digest('base64');

size(): Promise<number>

Defined in: src/ocfl-file.ts:46

Size in bytes.

Promise<number>

OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.

The file system error if the stored file is missing or can’t be read.

reply.header('content-length', await file.size());

stream(range?): Promise<Readable>

Defined in: src/ocfl-file.ts:66

Opens the content, or a byte range of it, as a stream. It rejects before resolving if the content can’t be read, so a server can still answer with an error status. Consume or destroy() the stream: until then it holds the stored file open.

Its chunks are Buffers. With DOM typings, copy one into a new Uint8Array before giving it to a Blob or Response. For a web stream, use Readable.toWeb(await file.stream()), and with DOM typings cast that to the global ReadableStream.

ByteRange

Promise<Readable>

RangeError if an end of the range isn’t a whole number from 0, start is after end, or start is after the last byte. An end after the last byte reads to the end.

OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.

The file system error if the stored file is missing or can’t be read.

// `start` and `end` from the request's `Range` header, checked against the size
const size = await file.size();
const body = await file.stream({ start, end });
reply.code(206).header('content-range', `bytes ${start}-${end}/${size}`).send(body);

text(): Promise<string>

Defined in: src/ocfl-file.ts:77

Reads the content as UTF-8 text.

Promise<string>

OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.

The file system error if the stored file is missing or can’t be read.

const metadata = JSON.parse(await file.text());