Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RichardKanshen/aee354019aa5b2316164aff8c253106d to your computer and use it in GitHub Desktop.
Save RichardKanshen/aee354019aa5b2316164aff8c253106d to your computer and use it in GitHub Desktop.
// fontBuffer is the Buffer of the font converted from base64
if (mimeType === 'font/woff2') {
// Check for the trailing 8-byte sequence
// because for SOME REASON Bun.build appends 7E 8A E6 6A DC 28 7D FD
// at the end of SOME WOFF2 fonts and it BREAKS EVERYTHING
const trailingBytes = Buffer.from([0x7E, 0x8A, 0xE6, 0x6A, 0xDC, 0x28, 0x7D, 0xFD]);
if (fontBufferSanitized.length >= 8) {
const last8Bytes = fontBuffer.subarray(fontBufferSanitized.length - 8);
if (last8Bytes.equals(trailingBytes)) {
fontBufferSanitized = fontBuffer.subarray(0, fontBufferSanitized.length - 8);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment