Skip to content

Minima.js API


Minima.js API / @minimajs/disk / plugins / compression

Function: compression()

ts
function compression(options?): (disk) => void;

Compression plugin — compresses files on put, decompresses on get.

Uses the Web API CompressionStream/DecompressionStream (Node 18+, all modern browsers).

Behavior depends on driver metadata support (capabilities.metadata):

  • true — algorithm is stored per-file in metadata; mixed compressed/uncompressed files are safe, and the correct algorithm is always used on read.
  • false or absent — algorithm is NOT stored; every file read through this disk is assumed to be compressed with the configured algorithm. Do not mix compressed and uncompressed files on the same disk.

Parameters

options?

CompressionOptions = {}

Returns

ts
(disk): void;

Parameters

disk

Disk

Returns

void

Examples

ts
const disk = createDisk({ driver }, compression())
await disk.put('file.txt', data)  // stored compressed
const file = await disk.get('file.txt')  // transparently decompressed
ts
// Custom algorithm
const disk = createDisk({ driver }, compression({ algorithm: 'deflate-raw' }))