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 = decode(woff2Data)

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

Performance

Benchmarks on an M1 Mac, Node 22. In Node, native Brotli (via zlib) is used; browsers use 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): Uint8Array

MIT, maintained by @jpt