Home / Hardware and Performance / Browser File Compressor

Browser File Compressor in JavaScript, Free with Live Demo

Free file compressor in plain JavaScript. Gzip or deflate any file and unpack .gz files with the native CompressionStream API, with streaming progress and size charts.

Open live demoDownload HTML fileView code on GitHub
Browser File Compressor JavaScript project: gzip any file or unpack a .gz right in the browser

Runs on: CompressionStream. Chrome and Edge 80+, Safari 16.4+, Firefox 113+.

What is the Browser File Compressor?

Drop a file to gzip it, or drop a .gz file to unpack it. You also get a text box that shows how well your text compresses, with before and after size bars.

The browser's own CompressionStream does the work, and the file is read as a stream, piece by piece, so big files never sit fully in memory. A small counting stream drives the progress bar.

Good for

  • Shrinking logs, CSV and JSON exports
  • Unpacking .gz downloads
  • Learning the Streams API
  • Tools that must work offline

What this project does

How it works

  1. Stream the filefile.stream() gives a ReadableStream, so the file is read piece by piece instead of all at once.
  2. Pipe through gzippipeThrough(new CompressionStream("gzip")) compresses each piece as it passes. A small TransformStream counts bytes for the progress bar.
  3. Collectnew Response(stream).blob() gathers the output into a file you can download.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

async function gzip(file, onProgress) {
  let done = 0;
  const counter = new TransformStream({
    transform(chunk, ctl) { done += chunk.byteLength; onProgress(done / file.size); ctl.enqueue(chunk); },
  });
  const stream = file.stream()
    .pipeThrough(counter)
    .pipeThrough(new CompressionStream("gzip"));
  return new Response(stream).blob();                  // collect the output
}
// Unpack: file.stream().pipeThrough(new DecompressionStream("gzip"))

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

What is CompressionStream?

A built in browser API that compresses or decompresses a stream with gzip, deflate or deflate raw. No library is needed.

Why do photos barely shrink?

JPEG, PNG, MP4 and zip files are already compressed. Text, CSV, JSON and code shrink the most.

Can it make .zip files?

No. Gzip works on one file at a time. Zip archives need a library such as fflate.

More Hardware and Performance projects