cross-7zip - v1.2.0
    Preparing search index...

    Class SevenZip

    A wrapper class for creating 7-Zip archives using the command-line tool.

    import { SevenZip } from 'cross-7zip';

    function createArchiveSync(): void {
    try {
    const zip = new SevenZip({
    destination: 'example.7z',
    files: ['document.txt', 'image.png', 'folder'],
    level: 5,
    passwrod: 'secure 123',
    overwrite: true
    });

    zip.runSync();
    console.log('Archive created successfully.');
    } catch (error) {
    console.error('An error occurred during compression:', error);
    }
    }

    async function createArchive(): Promise<void> {
    try {
    const zip = new SevenZip()
    .setDestination('example.7z')
    .setFiles(['document.txt', 'image.png', 'folder'])
    .setLevel(5)
    .setPassword('secure 123')
    .setOverwrite();

    await zip.run();
    console.log('Archive created successfully.');
    } catch (error) {
    console.error('An error occurred during compression:', error);
    }
    }

    For additional examples, see the sevenZipUnzip.test.ts or sevenZipUnzipSync.test.ts.

    Index

    Constructors

    Accessors

    • get args(): string[]

      Generates the arguments for the 7-Zip command-line execution.

      Returns string[]

    • get command(): undefined | string

      Gets the path to the 7-Zip executable.

      Returns undefined | string

    Methods

    • Runs the compression process asynchronously.

      Returns Promise<void>

      If the 7-Zip executable is not found.

    • Runs the compression process synchronously.

      Returns void

      If the 7-Zip executable is not found.

    • Sets the destination path for the output .7z file.

      Parameters

      • destination: string

        The output file path.

      Returns SevenZip

      The SevenZip instance for method chaining.

    • Sets the list of files and folders to be compressed.

      Parameters

      • files: string[]

        An array of file or directory paths.

      Returns SevenZip

      The SevenZip instance for method chaining.

    • Sets the compression level (1-9).

      Parameters

      • level: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

        Compression level, where 1 is the fastest and 9 is the best compression.

      Returns SevenZip

      The SevenZip instance for method chaining.

    • Enables overwrite mode, allowing an existing archive to be replaced.

      Parameters

      • overwrite: boolean = true

      Returns SevenZip

      The SevenZip instance for method chaining.

    • Sets a password for the archive.

      Parameters

      • password: string

        The encryption password.

      Returns SevenZip

      The SevenZip instance for method chaining.

    • Returns a string representation of the 7-Zip command with its arguments.

      This method constructs the full command-line string that would be executed, ensuring that each argument is properly quoted to handle paths with spaces.

      Returns string

      The formatted command-line string.