OcflFile
Defined in: src/ocfl-file.ts:17
A file in one version of an OCFL object.
Properties
Section titled “Properties”createdAt
Section titled “createdAt”
readonlycreatedAt: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.
createdIn
Section titled “createdIn”
readonlycreatedIn: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.
digest
Section titled “digest”
readonlydigest:string
Defined in: src/ocfl-file.ts:21
Lowercase hex digest of the content, in the object’s OcflObject.digestAlgorithm.
modifiedAt
Section titled “modifiedAt”
readonlymodifiedAt: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.
modifiedIn
Section titled “modifiedIn”
readonlymodifiedIn: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.
readonlypath:string
Defined in: src/ocfl-file.ts:19
Logical path within the version, such as audio/1.wav.
Methods
Section titled “Methods”bytes()
Section titled “bytes()”bytes():
Promise<Uint8Array<ArrayBuffer>>
Defined in: src/ocfl-file.ts:88
Reads the content into memory.
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBuffer>>
Throws
Section titled “Throws”OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.
Throws
Section titled “Throws”The file system error if the stored file is missing or can’t be read.
Example
Section titled “Example”const checksum = createHash('md5').update(await file.bytes()).digest('base64');size()
Section titled “size()”size():
Promise<number>
Defined in: src/ocfl-file.ts:46
Size in bytes.
Returns
Section titled “Returns”Promise<number>
Throws
Section titled “Throws”OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.
Throws
Section titled “Throws”The file system error if the stored file is missing or can’t be read.
Example
Section titled “Example”reply.header('content-length', await file.size());stream()
Section titled “stream()”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.
Parameters
Section titled “Parameters”range?
Section titled “range?”Returns
Section titled “Returns”Promise<Readable>
Throws
Section titled “Throws”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.
Throws
Section titled “Throws”OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.
Throws
Section titled “Throws”The file system error if the stored file is missing or can’t be read.
Example
Section titled “Example”// `start` and `end` from the request's `Range` header, checked against the sizeconst size = await file.size();const body = await file.stream({ start, end });reply.code(206).header('content-range', `bytes ${start}-${end}/${size}`).send(body);text()
Section titled “text()”text():
Promise<string>
Defined in: src/ocfl-file.ts:77
Reads the content as UTF-8 text.
Returns
Section titled “Returns”Promise<string>
Throws
Section titled “Throws”OcflError INVALID_OBJECT if the stored file isn’t a regular file, such as a directory.
Throws
Section titled “Throws”The file system error if the stored file is missing or can’t be read.
Example
Section titled “Example”const metadata = JSON.parse(await file.text());