# @e-mc/compress

> Compress constructor for E-mc.

Latest version **0.14.6** (published 2026-08-30) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @e-mc/compress
pnpm add @e-mc/compress
yarn add @e-mc/compress
bun add @e-mc/compress
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.14.6 |
| Published | 2026-08-30 |
| First published | 2023-03-03 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 51 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | An Pham |
| Maintainers | anpham6 |
| Keywords | squared |

## Links

- npm: https://www.npmjs.com/package/@e-mc/compress
- Repository: https://github.com/anpham6/e-mc
- Homepage: https://github.com/anpham6/e-mc#readme
- Issues: https://github.com/anpham6/e-mc/issues
- npm.io page: https://npm.io/package/@e-mc/compress

## Dependencies (4)

- [wawoff2](https://npm.io/package/wawoff2.md) ^2.0.1
- [@e-mc/core](https://npm.io/package/@e-mc/core.md) 0.14.6
- [@e-mc/types](https://npm.io/package/@e-mc/types.md) 0.14.6
- [woff2sfnt-sfnt2woff](https://npm.io/package/woff2sfnt-sfnt2woff.md) ^1.0.0

## Recent versions

- 0.14.6 (latest) — 2026-08-30
- 0.13.12 (T0Y0T1_YEN_B1N1N1_2022) — 2026-08-30
- 0.12.18 (T0Y0T1_YEN_B1N1N1_2021) — 2026-08-30
- 0.11.19 (T0Y0T1_YEN_B1N1N1_2020) — 2026-08-30
- 0.10.22 (forever99999999) — 2026-08-25
- 0.9.30 (succ0000000) — 2026-08-25
- 0.8.31 (succ000000) — 2026-08-25
- 0.7.25 (succ00000) — 2026-08-25
- 0.6.21 (succ0000) — 2026-08-25
- 0.5.23 (succ000) — 2026-08-25
- 0.13.11 (102_428_201) — 2026-07-06
- 0.12.17 (42_7) — 2026-07-06
- 0.11.18 (42_6) — 2026-07-06
- 0.10.21 (42_5) — 2026-07-06
- 0.9.29 (42_4) — 2026-07-06
- … 214 more at https://npm.io/package/@e-mc/compress/versions

## README

# @e-mc/compress

* NodeJS 20 (Minimum 18)
* ES2022

## General Usage

* [Read the Docs](https://e-mc.readthedocs.io)

## Interface

* [View Source](https://www.unpkg.com/@e-mc/types@0.14.6/lib/index.d.ts)

```typescript
import type { IModule, ModuleConstructor } from "./index";
import type { BrotliCompressLevel, BufferResult, CompressFormat, CompressLevel, ReadableOptions, TryFileCompressor } from "./compress";
import type { CompressModule, CompressSettings } from "./settings";

import type { WriteStream } from "node:fs";
import type { Readable } from "node:stream";
import type { BrotliCompress, BrotliOptions, Gzip, ZlibOptions } from "node:zlib";

interface ICompress extends IModule {
    module: CompressModule;
    level: Record<string, number>;
    compressors: Record<string, TryFileCompressor>;
    chunkSize?: number;
    init(...args: unknown[]): this;
    register(format: string, callback: TryFileCompressor): void;
    getLevel(value: string, fallback?: number): number | undefined;
    getReadable(file: string | URL | Buffer, options?: ReadableOptions): Readable;
    createGzip(file: string | Buffer, options?: CompressLevel): Gzip;
    createBrotliCompress(file: string | Buffer, options?: BrotliCompressLevel): BrotliCompress;
    createWriteStreamAsGzip(file: string | Buffer, output: string, options?: CompressLevel): WriteStream;
    createWriteStreamAsBrotli(file: string | Buffer, output: string, options?: BrotliCompressLevel): WriteStream;
    intoGzipStream(output: string, options?: ZlibOptions): WriteStream;
    intoBrotliStream(output: string, options?: BrotliOptions): WriteStream;
    writeGzip(file: string | Buffer, output: string, options?: CompressLevel): Promise<void>;
    writeBrotli(file: string | Buffer, output: string, options?: CompressLevel): Promise<void>;
    tryFile(file: string | Buffer, options: CompressFormat): Promise<BufferResult>;
    tryFile(file: string | Buffer, output: string, options?: CompressFormat): Promise<BufferResult>;
    tryImage(file: string, options: CompressFormat): Promise<BufferResult>;
    tryImage(file: string | Buffer, output: string, options?: CompressFormat): Promise<BufferResult>;
    hasPermission(type: string, options?: unknown): boolean;
    set chunkSize(value: number | string | undefined): void;
    get chunkSize(): number | undefined;
    get settings(): CompressSettings;
}

interface CompressConstructor extends ModuleConstructor {
    singleton(): ICompress;
    asBuffer(data: Buffer | Uint8Array): Buffer;
    readonly prototype: ICompress;
    new(module?: CompressModule): ICompress;
}
```

## Settings

```typescript
import type { CacheDirAction } from "./settings";

import type { BrotliOptions, ZlibOptions } from "node:zlib";

interface CompressModule {
    gzip?: ZlibOptions;
    brotli?: BrotliOptions;
    settings?: {
        broadcast_id?: string | string[];
        cache?: boolean | CacheDirAction & { font?: string | number | boolean; image?: string | number | boolean; };
        /** @deprecated cache.expires */
        cache_expires?: number | string;
        gzip_level?: number;
        brotli_quality?: number;
        chunk_size?: number | string;
    };
}
```

### Example usage

```javascript
const Compress = require("@e-mc/compress");

const instance = new Compress({
    gzip: {
        memLevel: 1,
        windowBits: 16
    },
    tinify: {
        api_key: "**********"
    },
    settings: {
        gzip_level: 9, // Lowest priority
        brotli_quality: 11,
        chunk_size: "16kb" // All compression types
    }
});
instance.init();

const stream = instance.createWriteStreamAsGzip("/tmp/archive.tar", "/path/output/archive.tar.gz", { level: 5, chunkSize: 4 * 1024 }); // Override settings
stream
    .on("finish", () => console.log("finish"))
    .on("error", err => console.error(err));

const options = {
    plugin: "@pi-r/tinify",
    format: "png", // Recommended
    timeout: 60 * 1000, // 1m
    options: {
        apiKey: "**********" // Override settings
    }
};
instance.tryImage("/tmp/image.png", "/path/output/compressed.png", options)
    .then(data => {
        console.log(Buffer.byteLength(data));
    })
    .catch(err => console.error(err));
```

## References

- https://www.unpkg.com/@e-mc/types@0.14.6/lib/compress.d.ts
- https://www.unpkg.com/@e-mc/types@0.14.6/lib/settings.d.ts

* https://www.npmjs.com/package/@types/node

## LICENSE

BSD 3-Clause

---
_Source: https://npm.io/package/@e-mc/compress · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
