Gzipper CLI and Module

8.2.1 · active · verified Wed Apr 22

Gzipper is a versatile command-line interface (CLI) tool and Node.js module designed for efficient file compression. It supports a comprehensive range of modern compression algorithms, including Deflate, Brotli, gzip, Zopfli, and zstd, providing developers with extensive control over the compression process. The current stable version is 8.2.1, with a regular release cadence as features and fixes are developed. Its key differentiators include fine-grained control over algorithm-specific parameters (e.g., `--gzip-level`, `--brotli-quality`), support for incremental compression, verbose output, and seamless integration with popular CLI UI tools like Angular CLI. It can compress entire directories by default or be configured with include/exclude patterns, and allows for custom output file formats. Environment variables take precedence over CLI arguments for configuration.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic usage of `gzipper` to compress a dummy file within a temporary directory using both Brotli and Gzip algorithms, with verbose output and cleanup.

import { compress } from 'gzipper';
import * as fs from 'node:fs';
import * as path from 'node:path';

const tempDir = path.join(process.cwd(), 'temp-gzipper-test');
const dummyFile = path.join(tempDir, 'example.txt');

async function runCompression() {
  // Create a temporary directory and file for testing
  if (!fs.existsSync(tempDir)) {
    fs.mkdirSync(tempDir, { recursive: true });
  }
  fs.writeFileSync(dummyFile, 'This is a test file to demonstrate gzipper compression. It should be long enough to get some compression benefit.', 'utf8');

  console.log('Compressing files in', tempDir);
  try {
    await compress(tempDir, tempDir, {
      brotli: true, // Enable Brotli compression
      gzip: true,   // Also enable Gzip compression
      outputFileFormat: '[name].[ext].br', // Brotli output format
      gzipOutputFileNameFormat: '[name].[ext].gz', // Gzip specific output format
      verbose: true,
      removeLarger: true // Remove original if compressed is smaller
    });
    console.log('Compression complete. Checking created files...');
    console.log('Files in temp directory:', fs.readdirSync(tempDir));
  } catch (error) {
    console.error('Compression failed:', error);
  } finally {
    // Clean up temporary files and directory
    if (fs.existsSync(tempDir)) {
      fs.rmSync(tempDir, { recursive: true, force: true });
      console.log('Cleaned up temporary directory:', tempDir);
    }
  }
}

runCompression();

view raw JSON →