or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

archive-control.mdarchive-creation.mdcontent-operations.mdformat-options.mdindex.md
tile.json

archive-creation.mddocs/

Archive Creation and Management

Core functionality for creating and managing archive instances with built-in format support and custom format registration.

Capabilities

Main Factory Function

Creates a new Archiver instance with the specified format and options.

/**
 * Creates a new Archiver instance
 * @param {string} format - Archive format ('zip', 'tar', 'json', defaults to 'zip')
 * @param {Object} options - Format-specific options
 * @returns {Archiver} Archiver instance that is a Transform stream
 */
function archiver(format, options);

Usage Examples:

const archiver = require('archiver');

// Create ZIP archive with compression
const zipArchive = archiver('zip', {
  zlib: { level: 9 } // Maximum compression
});

// Create TAR archive with gzip compression
const tarArchive = archiver('tar', {
  gzip: true,
  gzipOptions: {
    level: 1,
    chunkSize: 1024,
    windowBits: 15,
    memLevel: 8
  }
});

// Create JSON metadata archive
const jsonArchive = archiver('json');

// Default to ZIP format
const defaultArchive = archiver();

Alternative Creation Method

Alternative method for creating Archiver instances, functionally identical to the main factory function.

/**
 * Creates a new Archiver instance (alternative method)
 * @param {string} format - Archive format
 * @param {Object} options - Format-specific options
 * @returns {Archiver} Archiver instance
 */
archiver.create(format, options);

Usage Examples:

// Equivalent to archiver('zip', options)
const archive = archiver.create('zip', {
  zlib: { level: 5 }
});

Format Registration

Registers a custom archive format plugin for use with archiver.

/**
 * Registers a custom archive format
 * @param {string} format - Format name to register
 * @param {Function} module - Format module constructor function
 * @throws {Error} If format already registered or module invalid
 */
archiver.registerFormat(format, module);

Requirements for Format Modules:

  • Must be a constructor function
  • Prototype must have append(data, source, callback) method
  • Prototype must have finalize() method

Usage Examples:

// Custom format implementation
function CustomFormat(options) {
  this.options = options || {};
}

CustomFormat.prototype.append = function(data, source, callback) {
  // Implementation for appending entries
  callback();
};

CustomFormat.prototype.finalize = function() {
  // Implementation for finalizing archive
};

// Register the custom format
archiver.registerFormat('custom', CustomFormat);

// Now you can use the custom format
const customArchive = archiver('custom', { customOption: true });

Format Registration Check

Checks if a format is already registered and available for use.

/**
 * Checks if a format is already registered
 * @param {string} format - Format name to check
 * @returns {boolean} True if format is registered, false otherwise
 */
archiver.isRegisteredFormat(format);

Usage Examples:

// Check built-in formats
console.log(archiver.isRegisteredFormat('zip')); // true
console.log(archiver.isRegisteredFormat('tar')); // true
console.log(archiver.isRegisteredFormat('json')); // true
console.log(archiver.isRegisteredFormat('custom')); // false (unless registered)

// Check before registering to avoid errors
if (!archiver.isRegisteredFormat('myformat')) {
  archiver.registerFormat('myformat', MyFormatModule);
}

Built-in Formats

Archiver comes with three built-in formats that are automatically registered:

ZIP Format

  • Format name: 'zip'
  • Compression: Supports configurable compression levels
  • Features: Directory entries, symbolic links
  • Stream: Uses zip-stream engine

TAR Format

  • Format name: 'tar'
  • Compression: Optional gzip compression
  • Features: Directory entries, symbolic links
  • Stream: Uses tar-stream engine

JSON Format

  • Format name: 'json'
  • Output: JSON array of entry metadata
  • Features: Directory entries, symbolic links, CRC32 checksums
  • Use case: Metadata archiving and analysis

Error Handling

Format-related errors that may be thrown:

  • 'create(format): format not registered' - Attempting to create archive with unregistered format
  • 'register(format): format already registered' - Attempting to register a format that already exists
  • 'register(format): format module invalid' - Format module is not a function
  • 'register(format): format module missing methods' - Format module missing required append or finalize methods