### Install wawoff2 package Source: https://github.com/fontello/wawoff2/blob/master/README.md Install the library via npm. ```sh npm install wawoff2 ``` -------------------------------- ### Display CLI Help for woff2_decompress.js Source: https://context7.com/fontello/wawoff2/llms.txt Use the help flag to view usage instructions and available arguments for the decompressor CLI. ```bash woff2_decompress.js --help ``` -------------------------------- ### Compress font files via CLI Source: https://github.com/fontello/wawoff2/blob/master/README.md Use the command-line tool to convert a .ttf file to .woff2. ```bash woff2_compress.js [-h] [-v] infile [outfile] Positional arguments: infile Input .ttf file outfile Output .woff2 file (- for stdout) Optional arguments: -h, --help Show this help message and exit. -v, --version Show program's version number and exit. ``` -------------------------------- ### CLI: woff2_compress.js Source: https://context7.com/fontello/wawoff2/llms.txt Command-line tool for compressing TTF files to WOFF2 format. It can automatically determine the output filename or accept a custom path. Output can also be directed to stdout. ```APIDOC ## CLI: woff2_compress.js ### Description Compresses TTF files to WOFF2 format via the command line. ### Usage `woff2_compress.js [outfile]` ### Parameters #### Path Parameters - **infile** (string) - Required - Input .ttf file path. - **outfile** (string) - Optional - Output .woff2 file path. If omitted, defaults to the same directory with a .woff2 extension. Use `-` to write to stdout. ### Options - `-h`, `--help`: Show help message and exit. - `-v`, `--version`: Show program's version number and exit. ### Examples ```bash # Basic usage woff2_compress.js myfont.ttf # Specify custom output path woff2_compress.js myfont.ttf ./output/compressed.woff2 # Output to stdout woff2_compress.js myfont.ttf - > output.woff2 # Show version woff2_compress.js --version ``` ``` -------------------------------- ### Decompress font files via CLI Source: https://github.com/fontello/wawoff2/blob/master/README.md Use the command-line tool to convert a .woff2 file to .ttf. ```bash woff2_decompress.js [-h] [-v] infile [outfile] Positional arguments: infile Input .woff2 file outfile Output .ttf file (- for stdout) Optional arguments: -h, --help Show this help message and exit. -v, --version Show program's version number and exit. ``` -------------------------------- ### Compress Fonts via CLI Source: https://context7.com/fontello/wawoff2/llms.txt Uses the woff2_compress.js command-line tool to convert TTF files to WOFF2. ```bash # Basic usage - creates myfont.woff2 in same directory woff2_compress.js myfont.ttf # Specify custom output path woff2_compress.js myfont.ttf ./output/compressed.woff2 # Output to stdout (for piping) woff2_compress.js myfont.ttf - > output.woff2 # Show version woff2_compress.js --version # Show help woff2_compress.js --help # usage: woff2_compress.js [-h] [-v] infile [outfile] # # Positional arguments: # infile Input .ttf file # outfile Output .woff2 file (- for stdout) # # Optional arguments: # -h, --help Show this help message and exit. # -v, --version Show program's version number and exit. ``` -------------------------------- ### CLI: woff2_decompress.js Source: https://context7.com/fontello/wawoff2/llms.txt Command-line tool for decompressing WOFF2 files back to TTF format. It can automatically determine the output filename or accept a custom path. Output can also be directed to stdout. ```APIDOC ## CLI: woff2_decompress.js ### Description Decompresses WOFF2 files to TTF format via the command line. ### Usage `woff2_decompress.js [outfile]` ### Parameters #### Path Parameters - **infile** (string) - Required - Input .woff2 file path. - **outfile** (string) - Optional - Output .ttf file path. If omitted, defaults to the same directory with a .ttf extension. Use `-` to write to stdout. ### Options - `-h`, `--help`: Show help message and exit. - `-v`, `--version`: Show program's version number and exit. ### Examples ```bash # Basic usage woff2_decompress.js myfont.woff2 # Specify custom output path woff2_decompress.js myfont.woff2 ./output/decompressed.ttf # Output to stdout woff2_decompress.js myfont.woff2 - > output.ttf # Show version woff2_decompress.js --version ``` ``` -------------------------------- ### Round-trip Compression and Decompression Source: https://context7.com/fontello/wawoff2/llms.txt Demonstrates compressing a TTF font to WOFF2 and then decompressing it back to TTF, verifying the integrity of the round-trip conversion. ```APIDOC ## Round-trip Conversion ### Description Performs a round-trip conversion from TTF to WOFF2 and back to TTF, verifying data integrity. ### Parameters #### Path Parameters - **inputPath** (string) - Required - Path to the input TTF file. ### Returns - Object - An object containing `originalTtf`, `woff2Data`, and `restoredTtf`. ### Request Example ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); async function roundTripConversion(inputPath) { const originalTtf = Uint8Array.from(fs.readFileSync(inputPath)); console.log(`Original TTF size: ${originalTtf.length} bytes`); const woff2Data = await wawoff2.compress(originalTtf); console.log(`WOFF2 size: ${woff2Data.length} bytes`); const restoredTtf = await wawoff2.decompress(woff2Data); console.log(`Restored TTF size: ${restoredTtf.length} bytes`); const isIdentical = originalTtf.length === restoredTtf.length && originalTtf.every((byte, i) => byte === restoredTtf[i]); console.log(`Round-trip integrity: ${isIdentical ? 'PASSED' : 'FAILED'}`); return { originalTtf, woff2Data, restoredTtf }; } roundTripConversion('./fonts/sample.ttf').catch(console.error); ``` ``` -------------------------------- ### Decompress Fonts via CLI Source: https://context7.com/fontello/wawoff2/llms.txt Uses the woff2_decompress.js command-line tool to convert WOFF2 files back to TTF. ```bash # Basic usage - creates myfont.ttf in same directory woff2_decompress.js myfont.woff2 # Specify custom output path woff2_decompress.js myfont.woff2 ./output/decompressed.ttf # Output to stdout (for piping) woff2_decompress.js myfont.woff2 - > output.ttf # Show version woff2_decompress.js --version ``` -------------------------------- ### Compress font files programmatically Source: https://github.com/fontello/wawoff2/blob/master/README.md Compress a Buffer or Uint8Array using the wawoff2 library. ```js const wawoff = require('wawoff2'); // src - Buffer or Uint8Array wawoff.compress(src).then(out => { // store result }); ``` -------------------------------- ### Batch Compress TTF Fonts to WOFF2 Source: https://context7.com/fontello/wawoff2/llms.txt Automate the conversion of multiple TTF files in a directory to WOFF2 format using the wawoff2 library. ```javascript const fs = require('fs'); const path = require('path'); const wawoff2 = require('wawoff2'); async function batchCompress(inputDir, outputDir) { // Ensure output directory exists if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); } // Find all TTF files const files = fs.readdirSync(inputDir) .filter(file => file.toLowerCase().endsWith('.ttf')); console.log(`Found ${files.length} TTF files to compress`); for (const file of files) { const inputPath = path.join(inputDir, file); const outputPath = path.join(outputDir, file.replace(/\.ttf$/i, '.woff2')); try { const ttfData = fs.readFileSync(inputPath); const woff2Data = await wawoff2.compress(ttfData); fs.writeFileSync(outputPath, woff2Data); const ratio = ((1 - woff2Data.length / ttfData.length) * 100).toFixed(1); console.log(`${file}: ${ttfData.length} -> ${woff2Data.length} bytes (${ratio}% reduction)`); } catch (error) { console.error(`Failed to compress ${file}:`, error.message); } } } batchCompress('./fonts/source', './fonts/web').catch(console.error); ``` -------------------------------- ### Compress TTF to WOFF2 Source: https://context7.com/fontello/wawoff2/llms.txt Compresses a TTF font buffer to WOFF2 format. Takes a Buffer or Uint8Array containing TTF font data and returns a Promise that resolves to a Uint8Array with the compressed WOFF2 data. Throws an error if compression fails. ```APIDOC ## compress(buffer) ### Description Compresses a TTF font buffer to WOFF2 format. ### Parameters #### Request Body - **buffer** (Buffer | Uint8Array) - Required - TTF font data. ### Returns - Promise - A Promise that resolves to a Uint8Array with the compressed WOFF2 data. ### Throws - Error - If compression fails (e.g., invalid TTF input). ### Request Example ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); const ttfBuffer = fs.readFileSync('./fonts/myfont.ttf'); wawoff2.compress(ttfBuffer) .then(woff2Data => { fs.writeFileSync('./fonts/myfont.woff2', woff2Data); console.log(`Compressed: ${ttfBuffer.length} bytes -> ${woff2Data.length} bytes`); }) .catch(error => { console.error('Compression failed:', error.message); }); ``` ``` -------------------------------- ### Perform Round-trip Font Conversion Source: https://context7.com/fontello/wawoff2/llms.txt Verifies integrity by compressing a TTF to WOFF2 and immediately decompressing it back to TTF. ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); async function roundTripConversion(inputPath) { // Read original TTF const originalTtf = Uint8Array.from(fs.readFileSync(inputPath)); console.log(`Original TTF size: ${originalTtf.length} bytes`); // Compress to WOFF2 const woff2Data = await wawoff2.compress(originalTtf); console.log(`WOFF2 size: ${woff2Data.length} bytes`); // Decompress back to TTF const restoredTtf = await wawoff2.decompress(woff2Data); console.log(`Restored TTF size: ${restoredTtf.length} bytes`); // Verify integrity const isIdentical = originalTtf.length === restoredTtf.length && originalTtf.every((byte, i) => byte === restoredTtf[i]); console.log(`Round-trip integrity: ${isIdentical ? 'PASSED' : 'FAILED'}`); return { originalTtf, woff2Data, restoredTtf }; } roundTripConversion('./fonts/sample.ttf').catch(console.error); ``` -------------------------------- ### Decompress WOFF2 to TTF Source: https://context7.com/fontello/wawoff2/llms.txt Decompresses a WOFF2 font buffer back to TTF format. Takes a Buffer or Uint8Array containing WOFF2 font data and returns a Promise that resolves to a Uint8Array with the decompressed TTF data. Throws an error if decompression fails. ```APIDOC ## decompress(buffer) ### Description Decompresses a WOFF2 font buffer back to TTF format. ### Parameters #### Request Body - **buffer** (Buffer | Uint8Array) - Required - WOFF2 font data. ### Returns - Promise - A Promise that resolves to a Uint8Array with the decompressed TTF data. ### Throws - Error - If decompression fails (e.g., invalid WOFF2 input). ### Request Example ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); const woff2Buffer = fs.readFileSync('./fonts/myfont.woff2'); wawoff2.decompress(woff2Buffer) .then(ttfData => { fs.writeFileSync('./fonts/myfont-restored.ttf', ttfData); console.log(`Decompressed: ${woff2Buffer.length} bytes -> ${ttfData.length} bytes`); }) .catch(error => { console.error('Decompression failed:', error.message); }); ``` ``` -------------------------------- ### Compress TTF to WOFF2 Source: https://context7.com/fontello/wawoff2/llms.txt Compresses a TTF font buffer into WOFF2 format using the compress method. ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); // Read TTF font file const ttfBuffer = fs.readFileSync('./fonts/myfont.ttf'); // Compress to WOFF2 wawoff2.compress(ttfBuffer) .then(woff2Data => { // Save compressed font fs.writeFileSync('./fonts/myfont.woff2', woff2Data); console.log(`Compressed: ${ttfBuffer.length} bytes -> ${woff2Data.length} bytes`); console.log(`Compression ratio: ${((1 - woff2Data.length / ttfBuffer.length) * 100).toFixed(1)}%`); }) .catch(error => { console.error('Compression failed:', error.message); // Error: ConvertTTFToWOFF2 failed (invalid input) }); ``` -------------------------------- ### Decompress WOFF2 to TTF Source: https://context7.com/fontello/wawoff2/llms.txt Decompresses a WOFF2 font buffer back to TTF format using the decompress method. ```javascript const fs = require('fs'); const wawoff2 = require('wawoff2'); // Read WOFF2 font file const woff2Buffer = fs.readFileSync('./fonts/myfont.woff2'); // Decompress to TTF wawoff2.decompress(woff2Buffer) .then(ttfData => { // Save decompressed font fs.writeFileSync('./fonts/myfont-restored.ttf', ttfData); console.log(`Decompressed: ${woff2Buffer.length} bytes -> ${ttfBuffer.length} bytes`); }) .catch(error => { console.error('Decompression failed:', error.message); // Error: ConvertWOFF2ToTTF failed (invalid input) }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.