WoffCompressionContext
Index
Constructors
Methods
Constructors
constructor
new WoffCompressionContext(parallelism?: number): WoffCompressionContext
Create a new compression/decompression context.
Parameters
Optionalparallelism: numberThe number of worker threads to create. If not given, this will default to the number of cores on the system or
navigator.hardwareConcurrency.
Returns
WoffCompressionContext
Methods
getParallelism
compressFromTTF
compressFromTTF(
ttf: Uint8Array,
options: CompressOptions,
): Promise<Uint8Array<ArrayBuffer>>Compress an OpenType font file to WOFF or WOFF2.
Parameters
ttf: Uint8Array
The font file to compress. This must be a single font, not a collection.
options: CompressOptions
Options object.
Returns
Promise<Uint8Array<ArrayBuffer>>Compressed font data.
decompressToTTF
decompressToTTF(
compressed: Uint8Array,
options?: DecompressOptions,
): Promise<Uint8Array<ArrayBuffer>>Decompress a WOFF or WOFF2-compressed font file. Throws an error if the input font is not compressed.
Parameters
compressed: Uint8Array
The compressed font file data.
Optionaloptions: DecompressOptionsOptions object.
Returns
Promise<Uint8Array<ArrayBuffer>>Decompressed font file data.
destroy
destroy(): void
Destroy this context. All previous calls to this context's compression and decompression methods will resolve, but any further calls will error out.
If running in Node, Bun, Deno, or another such runtime, this will allow the program to exit once all font processing work is finished.
Returns
void
StaticcompressionType
compressionType(fontData: Uint8Array): null | "woff" | "woff2"
Return the compression type for a given font file.
Parameters
fontData: Uint8Array
The font file to check.
Returns
null | "woff" | "woff2"'woff' if the file is compressed with WOFF1, 'woff2' if it's compressed with WOFF2, or null if it's not compressed.
Context object for font compression and decompression. All operations are done off-thread using a worker pool. If running in an environment where your program is meant to exit by itself (e.g. on the command line), you must call WoffCompressionContext#destroy to close the worker threads and allow the program to exit.