Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

fflate

> 数据库
Open source

High performance (de)compression in an 8kB package

3.0K stars0 likes3 views
WebsiteGitHub

About

High performance (de)compression in an 8kB package

fflate

High performance (de)compression in an 8kB package

Why fflate?

fflate (short for fast flate) is the fastest, smallest, and most versatile pure JavaScript compression and decompression library in existence, handily beating pako, tiny-inflate, and UZIP.js in performance benchmarks while being multiple times more lightweight. Its compression ratios are often better than even the original Zlib C library. It includes support for DEFLATE, GZIP, and Zlib data. Data compressed by fflate can be decompressed by other tools, and vice versa.

In addition to the base decompression and compression APIs, fflate supports high-speed ZIP file archiving for an extra 3 kB. In fact, the compressor, in synchronous mode, compresses both more quickly and with a higher compression ratio than most compression software (even Info-ZIP, a C program), and in asynchronous mode it can utilize multiple threads to achieve over 3x the performance of virtually any other utility.

pako tiny-inflate UZIP.js fflate
Decompression performance 1x Up to 40% slower Up to 25% faster Up to 25% faster
Compression performance 1x N/A Up to 25% faster Up to 50% faster
Base bundle size (minified) 45.6kB 3kB (inflate only) 14.2kB 8kB (3kB for inflate only)
Decompression support ✅ ✅ ✅ ✅
Compression support ✅ ❌ ✅ ✅
ZIP support ❌ ❌ ✅ ✅
Streaming support ✅ ❌ ❌ ✅
GZIP support ✅ ❌ ❌ ✅
Supports files up to 4GB ✅ ❌ ❌ ✅
Doesn't hang on error ✅ ❌ ❌ ✅
Dictionary support ✅ ❌ ❌ ✅
Multi-thread/Asynchronous ❌ ❌ ❌ ✅
Streaming ZIP support ❌ ❌ ❌ ✅
Uses ES Modules ❌ ❌ ❌ ✅

Demo

If you'd like to try fflate for yourself without installing it, you can take a look at the browser demo. Since fflate is a pure JavaScript library, it works in both the browser and Node.js (see Browser support for more info).

Usage

Install fflate:

bash
npm i fflate # or yarn add fflate, or pnpm add fflate

Import:

javascript
// I will assume that you use the following for the rest of this guide
import * as fflate from 'fflate';

// However, you should import ONLY what you need to minimize bloat.
// So, if you just need GZIP compression support:
import { gzipSync } from 'fflate';
// Woo! You just saved 20 kB off your bundle with one line.

If your environment doesn't support ES Modules (e.g. Node.js):

javascript
// Try to avoid this when using fflate in the browser, as it will import
// all of fflate's components, even those that you aren't using.
const fflate = require('fflate');

If you want to load from a CDN in the browser:

xml

<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/umd/index.js"></script>

<script type="module">
  import * as fflate from 'https://cdn.skypack.dev/[email protected]?min';
</script>

If you are using Deno:

javascript
// Don't use the ?dts Skypack flag; it isn't necessary for Deno support
// The @deno-types comment adds TypeScript typings

// @deno-types="https://cdn.skypack.dev/[email protected]/lib/index.d.ts"
import * as fflate from 'https://cdn.skypack.dev/[email protected]?min';

If your environment doesn't support bundling:

javascript
// Again, try to import just what you need

// For the browser:
import * as fflate from 'fflate/esm/browser.js';
// If the standard ESM import fails on Node (i.e. older version):
import * as fflate from 'fflate/esm';

And use:

…

fflate can autodetect a compressed file's format as well:

javascript
const compressed = new Uint8Array(
  await fetch('/GZIPorZLIBorDEFLATE').then(res => res.arrayBuffer())
);
// Above example with Node.js Buffers:
// Buffer.from('H4sIAAAAAAAAE8tIzcnJBwCGphA2BQAAAA==', 'base64');

const decompressed = fflate.decompressSync(compressed);

Using strings is easy with fflate's string conversion API:

javascript
const buf = fflate.strToU8('Hello world!');

// The default compression method is gzip
// Increasing mem may increase performance at the cost of memory
// The mem ranges from 0 to 12, where 4 is the default
const compressed = fflate.compressSync(buf, { level: 6, mem: 8 });

// When you need to decompress:
const decompressed = fflate.decompressSync(compressed);
const origText = fflate.strFromU8(decompressed);
console.log(origText); // Hello world!

If you need to use an (albeit inefficient) binary string, you can set the second argument to true.

…

You can use streams as well to incrementally add data to be compressed or decompressed:

…

You can create multi-file ZIP archives easily as well. Note that by default, compression is enabled for all files, which is not useful when ZIPping many PNGs, JPEGs, PDFs, etc. because those formats are already compressed. You should either override the level on a per-file basis or globally to avoid wasting resources.

…

If you need extremely high performance or custom ZIP compression formats, you can use the highly-extensible ZIP streams. They take streams as both input and output. You can even use custom compression/decompression algorithms from other libraries, as long as they are defined in the ZIP spec (see section 4.4.5). If you'd like more info on using custom compressors, feel free to ask.

…

As you may have guessed, there is an asynchronous version of every method as well. Unlike most libraries, this will cause the compression or decompression run in a separate thread entirely and automatically by using Web (or Node) Workers. This means that the processing will not block the main thread at all.

Note that there is a significant initial overhead to using workers of about 50ms for each asynchronous function. For instance, if you call unzip ten times, the overhead only applies for the first call, but if you call unzip and zlib, they will each cause the 50ms delay. For small (under about 50kB) payloads, the asynchronous APIs will be much slower. However, if you're compressing larger files/multiple files at once, or if the synchronous API causes the main thread to hang for too long, the callback APIs are an order of magnitude better.

…

See the documentation for more detailed information about the API.

Bundle size estimates

The bundle size measurements for fflate on sites like Bundlephobia include every feature of the library and should be seen as an upper bound. As long as you are using tree shaking or dead code elimination, this table should give you a general idea of fflate's bundle size for the features you need.

The maximum bundle size that is possible with fflate is about 33kB (12.5kB gzipped) if you use every single feature, but feature parity with pako is only around 10kB (as opposed to 45kB from pako). If your bundle size increases dramatically after adding fflate, please create an issue.

Feature Bundle size (minified) Nearest competitor
Decompression 3kB tiny-inflate
Compression 5kB UZIP.js, 2.84x larger
Async decompression 4kB (1kB + raw decompression) N/A
Async compression 6kB (1kB + raw compression) N/A
ZIP decompression 5kB (2kB + raw decompression) UZIP.js, 2.84x larger
ZIP compression 7kB (2kB + raw compression) UZIP.js, 2.03x larger
GZIP/Zlib decompression 4kB (1kB + raw decompression) pako, 11.4x larger
GZIP/Zlib compression 5kB (1kB + raw compression) pako, 9.12x larger
Streaming decompression 4kB (1kB + raw decompression) pako, 11.4x larger
Streaming compression 5kB (1kB + raw compression) pako, 9.12x larger

What makes fflate so fast?

Many JavaScript compression/decompression libraries exist. However, the most popular one, pako, is merely a clone of Zlib rewritten nearly line-for-line in JavaScript. Although it is by no means poorly made, pako doesn't recognize the many differences between JavaScript and C, and therefore is suboptimal for performance. Moreover, even when minified, the library is 45 kB; it may not seem like much, but for anyone concerned with optimizing bundle size (especially library authors), it's more weight than necessary.

Note that there exist some small libraries like tiny-inflate for solely decompression, and with a minified size of 3 kB, it can be appealing; however, its performance is lackluster, typically 40% worse than pako in my tests.

UZIP.js is both faster (by up to 25%) and smaller (14 kB minified) than pako, and it contains a variety of innovations that make it excellent for both performance and compression ratio. However, the developer made a variety of tiny mistakes and inefficient design choices that make it imperfect. Moreover, it does not support GZIP or Zlib data directly; one must remove the headers manually to use UZIP.js.

So what makes fflate different? It takes the brilliant innovations of UZIP.js and optimizes them while adding direct support for GZIP and Zlib data. And unlike all of the above libraries, it uses ES Modules to allow for partial builds through tree shaking, meaning that it can rival even tiny-inflate in size while maintaining excellent performance. The end result is a library that, in total, weighs 8kB minified for the core build (3kB for decompression only and 5kB for compression only), is about 25% faster than UZIP.js or up to 50% faster than pako, and achieves the same or better compression ratio than the rest.

Before you decide that fflate is the end-all compression library, you should note that JavaScript simply cannot rival the performance of a native program. If you're only using Node.js, it's probably better to use the native Zlib bindings, which tend to offer the best performance. Though note that even against Zlib, fflate is only around 30% slower in decompression and 10% slower in compression, and can still achieve better comp

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptcompressiondecompressionhigh-performancepako

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库