Skip to content

countertype/woff2-decode

Repository files navigation

woff2-decode

npm version license

A TypeScript WOFF2 decoder

Installation

npm install woff2-decode

Usage

import { decode } from 'woff2-decode'

const woff2Data = await fetch('/font.woff2').then(r => r.arrayBuffer())
const ttfData = await decode(woff2Data)

// ttfData is a Uint8Array containing the decoded TTF/OTF

Performance

Benchmarks on an M2 Max, Node 22. Native Brotli is used in Node (via zlib) and browsers that support DecompressionStream('brotli') (Firefox 113+, Safari 16.4+). Chrome falls back to pure JS

File Size Native Pure JS
enc-otf.woff2 (CFF) 107 KB 1.6 ms 5.3 ms
enc-ttf.woff2 98 KB 2.4 ms 5.5 ms
enc-var-ttf.woff2 318 KB 5.2 ms 14.4 ms

API

function decode(data: ArrayBuffer | Uint8Array): Promise<Uint8Array>

MIT, maintained by @jpt