Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ZipFile

open返回的对象,用于在压缩包中增删文件、获取文件头信息、解压等。

Hierarchy

  • ZipFile

Index

Methods

addFile

  • addFile(file: string, options?: ZipOptions): Promise<void>
  • Add a file to the ZIP file.

    example
    const zip = require('zip);
    async function main() {
        const zipFile = await zip.open('test.zip');
        await zipFile.addFile('test.txt');
    }
    main();
    

    Parameters

    • file: string

      Local file path

    • Optional options: ZipOptions

      Compress options

    Returns Promise<void>

addFiles

  • addFiles(fileList: string[], options?: ZipOptions): Promise<void>
  • Add multiple files to the ZIP file.

    Parameters

    • fileList: string[]

      Array of local file paths

    • Optional options: ZipOptions

      Compress options

    Returns Promise<void>

addFolder

  • addFolder(folder: string, options?: ZipOptions): Promise<void>
  • Add a folder to the ZIP file.

    Parameters

    • folder: string

      Folder path

    • Optional options: ZipOptions

      Compress options

    Returns Promise<void>

extractAll

  • extractAll(dest: string, options?: UnzipOptions): Promise<void>
  • Extract all files from the ZIP file to the target path dest.

    Parameters

    • dest: string

      Extract path

    • Optional options: UnzipOptions

      Extract options

    Returns Promise<void>

extractFile

  • extractFile(file: string, dest: string, options?: UnzipOptions, newFileName?: string): Promise<void>
  • Extract a file from the ZIP file. If the target path is invalid, this method will throw an exception.

    Parameters

    • file: string

      File to extract

    • dest: string

      Destination path

    • Optional options: UnzipOptions

      Extract options

    • Optional newFileName: string

      New file name, optional

    Returns Promise<void>

getFileHeader

  • getFileHeader(file: string): any

getFileHeaders

  • getFileHeaders(): any[]
  • Get the file header information of all files in the ZIP file. The file header information includes the checksum, whether the file is encrypted, comments, etc.

    Returns any[]

    Array of FileHeader

getPath

  • getPath(): string
  • Get the path of the current ZIP file.

    Returns string

isEncrypted

  • isEncrypted(): boolean
  • Get whether the current ZIP file is an encrypted ZIP file.

    Returns boolean

    Whether the current ZIP file is an encrypted ZIP file.

isValidZipFile

  • isValidZipFile(): boolean
  • Get whether the current ZIP file is a valid ZIP file. If the path is not a ZIP file or the file does not exist, return false.

    Returns boolean

    Whether the current ZIP file is a valid ZIP file.

removeFile

  • removeFile(file: string): Promise<void>
  • Delete a file from the ZIP file. If the file does not exist, this method will throw an exception.

    If the ZIP file is a segmented ZIP file, this method will throw an exception, because the zip specification does not allow updating a segmented ZIP file.

    Parameters

    • file: string

      File to delete

    Returns Promise<void>

setPassword

  • setPassword(password: string): void
  • If the ZIP file is encrypted, you must use this function to set the correct password to decrypt the encrypted file. If you do not set the password, an exception will be thrown when you try to decrypt the encrypted ZIP file.

    Parameters

    • password: string

      Password

    Returns void