Archiver Utilities

5.0.2 · active · verified Sun Apr 19

archiver-utils provides essential utility functions designed to support the `archiver` package, primarily focusing on file system and stream operations. As of its current stable version, 5.0.2, it offers robust capabilities for tasks such as directory traversal (`fs.walkdir`) and stream interface detection (`stream.detect`). The package maintains a relatively frequent release cadence, often aligning major version updates with Node.js EOL cycles and significant dependency upgrades. Key differentiators include its tight integration with the `archiver` ecosystem, providing specialized helpers that enhance the core archiving functionality, ensuring efficient and reliable handling of file and stream inputs. It is not intended as a standalone archiving solution but as a foundational helper for `archiver` itself.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to use `fs.walkdir` to recursively traverse a directory and log file/directory information, then cleans up.

import { fs } from 'archiver-utils';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import * as nodeFs from 'node:fs';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Create a dummy directory structure for demonstration
const tempDir = join(__dirname, 'temp_walkdir_test');
const subDir = join(tempDir, 'subfolder');
nodeFs.mkdirSync(subDir, { recursive: true });
nodeFs.writeFileSync(join(tempDir, 'file1.txt'), 'Content 1');
nodeFs.writeFileSync(join(subDir, 'file2.txt'), 'Content 2');
nodeFs.writeFileSync(join(tempDir, 'another-file.js'), 'console.log("hello");');

console.log(`Walking directory: ${tempDir}`);

fs.walkdir(tempDir, (filepath, stats) => {
  if (stats.isDirectory()) {
    console.log(`[DIR] ${filepath}`);
  } else {
    console.log(`[FILE] ${filepath} (size: ${stats.size} bytes)`);
  }
}, (err) => {
  if (err) {
    console.error('Error during walkdir:', err);
  } else {
    console.log('Walkdir complete.');
  }

  // Clean up the dummy directory
  nodeFs.rmSync(tempDir, { recursive: true, force: true });
  console.log('Cleaned up temp directory.');
});

view raw JSON →