@types/adm-zip

  • Version 0.4.34
  • Published
  • 14.4 kB
  • 1 dependency
  • MIT license

Install

npm i @types/adm-zip
yarn add @types/adm-zip
pnpm add @types/adm-zip

Overview

TypeScript definitions for adm-zip

Index

Classes

class AdmZip

class AdmZip {}

    constructor

    constructor(fileNameOrRawData?: any);
    • Parameter fileNameOrRawData

      If provided, reads an existing archive. Otherwise creates a new, empty archive.

    method addFile

    addFile: (entryName: string, data: any, comment?: string, attr?: number) => void;
    • Allows you to create a entry (file or directory) in the zip file. If you want to create a directory the entryName must end in "/" and a null buffer should be provided.

      Parameter entryName

      Entry path.

      Parameter content

      Content to add to the entry; must be a 0-length buffer for a directory.

      Parameter comment

      Comment to add to the entry.

      Parameter attr

      Attribute to add to the entry.

    method addLocalFile

    addLocalFile: (localPath: string, zipPath?: string, zipName?: string) => void;
    • Adds a file from the disk to the archive.

      Parameter localPath

      Path to a file on disk.

      Parameter zipPath

      Path to a directory in the archive. Defaults to the empty string.

      Parameter zipName

      Name for the file.

    method addLocalFolder

    addLocalFolder: (
    localPath: string,
    zipPath?: string,
    filter?: RegExp | ((filename: string) => boolean)
    ) => void;
    • Adds a local directory and all its nested files and directories to the archive.

      Parameter localPath

      Path to a folder on disk.

      Parameter zipPath

      Path to a folder in the archive. Default: "".

      Parameter filter

      RegExp or Function if files match will be included.

    method addZipComment

    addZipComment: (comment: string) => void;
    • Adds a comment to the zip. The zip must be rewritten after adding the comment.

      Parameter comment

      Content of the comment.

    method addZipEntryComment

    addZipEntryComment: (entry: string | AdmZip.IZipEntry, comment: string) => void;
    • Adds a comment to a specified file or IZipEntry. The zip must be rewritten after adding the comment. The comment cannot exceed 65535 characters in length.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter comment

      The comment to add to the entry.

    method deleteFile

    deleteFile: (entry: string | AdmZip.IZipEntry) => void;
    • Remove the entry from the file or the entry and all its nested directories and files if the given entry is a directory.

      Parameter entry

      The full path of the entry or a IZipEntry object.

    method extractAllTo

    extractAllTo: (targetPath: string, overwrite?: boolean) => void;
    • Extracts the entire archive to the given location.

      Parameter targetPath

      Target location.

      Parameter overwrite

      If the file already exists at the target path, the file will be overwriten if this is true. Default: false.

    method extractAllToAsync

    extractAllToAsync: (
    targetPath: string,
    overwrite?: boolean,
    callback?: (error: Error) => void
    ) => void;
    • Extracts the entire archive to the given location.

      Parameter targetPath

      Target location.

      Parameter overwrite

      If the file already exists at the target path, the file will be overwriten if this is true. Default: false.

      Parameter callback

      The callback function will be called after extraction.

    method extractEntryTo

    extractEntryTo: (
    entryPath: string | AdmZip.IZipEntry,
    targetPath: string,
    maintainEntryPath?: boolean,
    overwrite?: boolean
    ) => boolean;
    • Extracts the given entry to the given targetPath. If the entry is a directory inside the archive, the entire directory and its subdirectories will be extracted.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter targetPath

      Target folder where to write the file.

      Parameter maintainEntryPath

      If maintainEntryPath is true and the entry is inside a folder, the entry folder will be created in targetPath as well. Default: true.

      Parameter overwrite

      If the file already exists at the target path, the file will be overwriten if this is true. Default: false.

    method getEntries

    getEntries: () => AdmZip.IZipEntry[];
    • Returns an array of IZipEntry objects representing the files and folders inside the archive.

    method getEntry

    getEntry: (name: string) => AdmZip.IZipEntry | null;
    • Returns a IZipEntry object representing the file or folder specified by name.

      Parameter name

      Name of the file or folder to retrieve. The entry corresponding to the name.

    method getZipComment

    getZipComment: () => string;
    • The zip comment.

    method getZipEntryComment

    getZipEntryComment: (entry: string | AdmZip.IZipEntry) => string;
    • Returns the comment of the specified entry.

      Parameter entry

      The full path of the entry or a IZipEntry object. The comment of the specified entry.

    method readAsText

    readAsText: (fileName: string | AdmZip.IZipEntry, encoding?: string) => string;
    • Extracts the given entry from the archive and returns the content as plain text in the given encoding.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter encoding

      If no encoding is specified "utf8" is used.

    method readAsTextAsync

    readAsTextAsync: (
    fileName: string | AdmZip.IZipEntry,
    callback: (data: string, err: string) => any,
    encoding?: string
    ) => void;
    • Asynchronous readAsText.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter callback

      Called with the resulting string.

      Parameter encoding

      If no encoding is specified "utf8" is used.

    method readFile

    readFile: (entry: string | AdmZip.IZipEntry) => Buffer | null;
    • Extracts the given entry from the archive and returns the content.

      Parameter entry

      The full path of the entry or a IZipEntry object. Buffer or null in case of error.

    method readFileAsync

    readFileAsync: (
    entry: string | AdmZip.IZipEntry,
    callback: (data: Buffer | null, err: string) => any
    ) => void;
    • Asynchronous readFile.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter callback

      Called with a Buffer or null in case of error.

    method test

    test: () => boolean;
    • Test the archive.

    method toBuffer

    toBuffer: {
    (): any;
    (
    onSuccess: (buffer: any) => void,
    onFail?: (...args: any[]) => void,
    onItemStart?: (name: string) => void,
    onItemEnd?: (name: string) => void
    ): void;
    };
    • Returns the content of the entire zip file.

    • Asynchronously returns the content of the entire zip file.

      Parameter onSuccess

      called with the content of the zip file, once it has been generated.

      Parameter onFail

      unused.

      Parameter onItemStart

      called before an entry is compressed.

      Parameter onItemEnd

      called after an entry is compressed.

    method updateFile

    updateFile: (entry: string | AdmZip.IZipEntry, content: any) => void;
    • Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content.

      Parameter entry

      The full path of the entry or a IZipEntry object.

      Parameter content

      The entry's new contents.

    method writeZip

    writeZip: (
    targetFileName?: string,
    callback?: (error: Error | null) => void
    ) => void;
    • Writes the newly created zip file to disk at the specified location or if a zip was opened and no targetFileName is provided, it will overwrite the opened zip.

    Interfaces

    interface DataHeader

    interface DataHeader {}

      property compressedSize

      compressedSize: number;

        property crc

        crc: number;

          property extraLen

          extraLen: number;

            property flags

            flags: number;

              property fnameLen

              fnameLen: number;

                property method

                method: number;

                  property size

                  size: number;

                    property time

                    time: number;

                      property version

                      version: number;

                        interface EntryHeader

                        interface EntryHeader {}

                          property attr

                          attr: number;

                            property commentLength

                            commentLength: number;

                              property compressedSize

                              compressedSize: number;

                                property crc

                                crc: number;

                                  property dataHeader

                                  readonly dataHeader: DataHeader;

                                    property diskNumStart

                                    diskNumStart: number;

                                      property encripted

                                      readonly encripted: boolean;

                                        property entryHeaderSize

                                        readonly entryHeaderSize: number;

                                          property extraLength

                                          extraLength: number;

                                            property fileNameLength

                                            fileNameLength: number;

                                              property flags

                                              flags: number;

                                                property inAttr

                                                inAttr: number;

                                                  property made

                                                  made: number;

                                                    property method

                                                    method: number;

                                                      property offset

                                                      offset: number;

                                                        property realDataOffset

                                                        readonly realDataOffset: number;

                                                          property size

                                                          size: number;

                                                            property time

                                                            time: Date;

                                                              property version

                                                              version: number;

                                                                method dataHeaderToBinary

                                                                dataHeaderToBinary: () => any;

                                                                  method entryHeaderToBinary

                                                                  entryHeaderToBinary: () => any;

                                                                    method loadDataHeaderFromBinary

                                                                    loadDataHeaderFromBinary: (data: any) => void;

                                                                      method loadFromBinary

                                                                      loadFromBinary: (data: any) => void;

                                                                        method toString

                                                                        toString: () => string;

                                                                          interface IZipEntry

                                                                          interface IZipEntry {}
                                                                          • The IZipEntry is more than a structure representing the entry inside the zip file. Beside the normal attributes and headers a entry can have, the class contains a reference to the part of the file where the compressed data resides and decompresses it when requested. It also compresses the data and creates the headers required to write in the zip file.

                                                                          property attr

                                                                          attr: number;

                                                                            property comment

                                                                            comment: string;
                                                                            • Entry comment.

                                                                            property entryName

                                                                            entryName: string;
                                                                            • Represents the full name and path of the file

                                                                            property extra

                                                                            extra: Buffer;
                                                                            • Extra data associated with this entry.

                                                                            property header

                                                                            readonly header: EntryHeader;
                                                                            • Get the header associated with this ZipEntry.

                                                                            property isDirectory

                                                                            readonly isDirectory: boolean;
                                                                            • Read-Only property that indicates the type of the entry.

                                                                            property name

                                                                            readonly name: string;

                                                                              property rawEntryName

                                                                              readonly rawEntryName: Buffer;

                                                                                method getCompressedData

                                                                                getCompressedData: () => any;
                                                                                • Retrieve the compressed data for this entry. Note that this may trigger compression if any properties were modified.

                                                                                method getCompressedDataAsync

                                                                                getCompressedDataAsync: (callback: (data: any) => void) => void;
                                                                                • Asynchronously retrieve the compressed data for this entry. Note that this may trigger compression if any properties were modified.

                                                                                method getData

                                                                                getData: () => any;
                                                                                • Get the decompressed data associated with this entry.

                                                                                method getDataAsync

                                                                                getDataAsync: (callback: (data: any, err: string) => any) => void;
                                                                                • Asynchronously get the decompressed data associated with this entry.

                                                                                method packHeader

                                                                                packHeader: () => any;
                                                                                • Returns the CEN Entry Header to be written to the output zip file, plus the extra data and the entry comment.

                                                                                method setData

                                                                                setData: (value: string | Buffer) => void;
                                                                                • Set the (uncompressed) data to be associated with this entry.

                                                                                method toString

                                                                                toString: () => string;
                                                                                • Returns a nicely formatted string with the most important properties of the ZipEntry.

                                                                                Package Files (1)

                                                                                Dependencies (1)

                                                                                Dev Dependencies (0)

                                                                                No dev dependencies.

                                                                                Peer Dependencies (0)

                                                                                No peer dependencies.

                                                                                Badge

                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/adm-zip.

                                                                                • Markdown
                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/adm-zip)
                                                                                • HTML
                                                                                  <a href="https://www.jsdocs.io/package/@types/adm-zip"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>