Skip to content

Latest commit

 

History

History
114 lines (77 loc) · 4.35 KB

File metadata and controls

114 lines (77 loc) · 4.35 KB

Enterprise Binary & Asset Processors Guide

Condense v1.0.0 delivers Pillar 2: Enterprise Binary & Asset Processors, expanding beyond raster images and standard text to include specialized, high-performance in-memory optimizers for ZIP archives, SVG icon spritesheets, font files, and PDF documents.


1. In-Memory Recursive ZIP Archive Optimizer (optimizeZip)

Standard archive compressors (like standard zip) do not optimize the files inside the archive before compressing them.

optimizeZip performs pure in-memory decompression, identifies the MIME type of each individual file inside the archive, applies Condense's format-specific optimization pipelines (images, code, fonts, documents), and repacks the archive using maximum-ratio DEFLATE compression via fflate.

Key Benefits

  • Zero Disk Writes: Safe for serverless environments and memory-only workers.
  • Deep Compression: Optimizes images, scripts, stylesheets, and markup inside the archive prior to repacking.
  • Preserves File Structure: Retains file paths, timestamps, and directory hierarchies.

Usage Example

const { optimizeZip } = require('@studioframes/condense');
const fs = require('fs');

const rawZipBuffer = fs.readFileSync('distribution.zip');

const { buffer, originalSize, optimizedSize, processedFiles } = await optimizeZip(rawZipBuffer, {
  method: 'extreme',   // 'quality', 'balanced', or 'extreme'
  level: 9,            // DEFLATE level (0-9, default: 9)
});

console.log(`Optimized ${processedFiles} files.`);
console.log(`Reduced from ${originalSize} to ${optimizedSize} bytes.`);

2. In-Memory SVG Spritesheet Packer (packSvgSprites)

Serving dozens of individual SVG icon requests creates network overhead and HTTP round-trips. Embedding SVGs inline can bloat HTML documents.

packSvgSprites parses an array or map of SVG icon files, extracts their viewBox definitions and inner vector markup, strips redundant XML declarations and comments, and packs them into a single, clean <svg><defs><symbol> spritesheet.

Usage Example

const { packSvgSprites } = require('@studioframes/condense');

const icons = [
  {
    id: 'icon-search',
    content: '<svg viewBox="0 0 24 24"><path d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>',
  },
  {
    id: 'icon-user',
    content: '<svg viewBox="0 0 24 24"><circle cx="12" cy="7" r="4"/><path d="M4 21v-2a4 4 0 014-4h8a4 4 0 014 4v2"/></svg>',
  },
];

const spritesheet = packSvgSprites(icons);

Using the Spritesheet in Frontend HTML

<!-- Load spritesheet once at the top of the body or via external reference -->
<svg style="display:none">
  <!-- spritesheet content -->
</svg>

<!-- Render icons effortlessly with <use> tags -->
<svg class="icon"><use href="#icon-search"></use></svg>
<svg class="icon"><use href="#icon-user"></use></svg>

3. Font Table Stripper (optimizeFont)

TrueType (.ttf) and OpenType (.otf) fonts often include legacy hinting tables, digital signatures, and unused device metrics that add weight to web font downloads without providing visual benefit in modern browsers.

optimizeFont parses the SFNT / WOFF binary table directory, identifies discardable tables (such as DSIG, hdmx, LTSH, PCLT), recalculates the table directory offsets and checksums, and outputs a stripped binary font.

Usage Example

const { optimizeFont } = require('@studioframes/condense');

const { buffer, droppedTables, byteLength } = await optimizeFont(rawTtfBuffer, 'font/ttf', {
  tablesToDrop: ['DSIG', 'hdmx', 'LTSH', 'PCLT'],
});

console.log(`Dropped tables: ${droppedTables.join(', ')}`);
console.log(`New font size: ${byteLength} bytes`);

4. In-Memory PDF Optimizer (optimizePdf)

PDF files generated by design tools or office suites often contain unreferenced objects, verbose comments, embedded XML metadata (XMP packets), and uncompressed text streams.

optimizePdf performs pure in-memory cleaning:

  • Strips PDF comments (% ...)
  • Removes XML metadata streams (<x:xmpmeta>...</x:xmpmeta>)
  • Cleans trailing unreferenced whitespaces and compacts object definitions.

Usage Example

const { optimizePdf } = require('@studioframes/condense');

const { buffer, originalSize, optimizedSize } = await optimizePdf(rawPdfBuffer);
console.log(`PDF size reduced from ${originalSize} to ${optimizedSize} bytes`);