Options
All
  • Public
  • Public/Protected
  • All
Menu

Module zip

The Zip module provides APIs to handle file compression and decompression, and supports encryption.

see

zip4j

Index

Type aliases

ZipFileAttribute

ZipFileAttribute: "all" | "archive" | "dateTime" | "hidden" | "system" | "readOnly"

Functions

open

  • Open a zip file and return a ZipFile object. You can perform more operations on the returned object.

    Parameters

    • file: string

      The path of the zip file.

    Returns ZipFile

unzip

  • unzip(zipFile: string, dest: string, options?: UnzipOptions): Promise<void>
  • Unzip a zip file. If dest directory does not exist, create it and unzip the content to it; if dest directory exists, create a folder with the same name as zipFile in dest and unzip the content to it.

    example
    "nodejs";
    const { unzip, zipDir } = require('zip');
    
    async function main() {
        // create a zip file with password
        const zipFilePath = './dest.zip';
        await zipDir('./dir', zipFilePath, { password: 'Auto.js Pro' });
        // unzip the zip file
        await unzip(zipFilePath, './dest', { password: 'Auto.js Pro' });
    }
    main();
    

    Parameters

    • zipFile: string
    • dest: string
    • Optional options: UnzipOptions

    Returns Promise<void>

zipDir

  • Compress all files and folders under dir to dest.

    example
    const { zipDir } = require('zip');
    zipDir('./dir', './dest.zip')
     .then(zipFile => console.log(zipFile));
    

    Parameters

    • dir: string

      The path of the folder to be compressed.

    • dest: string

      The path of the target zip file.

    • Optional options: ZipOptions

      Optional parameters.

    Returns Promise<ZipFile>

zipFile

  • Compress a single file file to dest.

    example
    const { zipFile } = require('zip');
    zipFile('./file.txt', './dest.zip')
     .then(zipFile => console.log(zipFile));
    

    Parameters

    • file: string

      The path of the file to be compressed.

    • dest: string

      The path of the target zip file.

    • Optional options: ZipOptions

      Optional parameters.

    Returns Promise<ZipFile>

zipFiles

  • Compress multiple files fileList to dest. fileList cannot contain folders.

    example
    const { zipFiles } = require('zip');
    zipFiles(['./file1.txt', './file2.txt'], './dest.zip')
     .then(zipFile => console.log(zipFile));
    

    Parameters

    • fileList: string[]

      The array of paths of the files to be compressed.

    • dest: string

      The path of the target zip file.

    • Optional options: ZipOptions

      Optional parameters.

    Returns Promise<ZipFile>