@types/adm-zip

  • Version 0.5.7
  • Published
  • 24.6 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, options?: Partial<AdmZip.InitOptions>);
    • Parameter fileNameOrRawData

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

      Parameter options

      Options when initializing the ZIP file

    method addFile

    addFile: (
    entryName: string,
    content: Buffer,
    comment?: string,
    attr?: number
    ) => AdmZip.IZipEntry;
    • 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. The entry corresponding to one which was just added.

    method addLocalFile

    addLocalFile: (
    localPath: string,
    zipPath?: string,
    zipName?: string,
    comment?: 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.

      Parameter comment

      Comment to be attached to 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 addLocalFolderAsync

    addLocalFolderAsync: (
    localPath: string,
    callback: (success?: boolean, err?: string) => void,
    zipPath?: string,
    filter?: RegExp | ((filename: string) => boolean)
    ) => void;
    • Asynchronous addLocalFile

      Parameter localPath

      Parameter callback

      Parameter zipPath

      optional path inside zip

      Parameter filter

      optional RegExp or Function if files match will be included.

    method addLocalFolderPromise

    addLocalFolderPromise: (
    localPath: string,
    props: {
    zipPath?: string;
    filter?: RegExp | ((filename: string) => boolean);
    }
    ) => Promise<void>;
    • Parameter localPath

      path where files will be extracted

      Parameter props

      optional properties

      Parameter

      props.zipPath - optional path inside zip

      Parameter

      props.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,
    keepOriginalPermission?: boolean,
    password?: string | Buffer
    ) => 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 keepOriginalPermission

      The file will be set as the permission from the entry if this is true. Default: false.

      Parameter password

      The password for the archive

    method extractAllToAsync

    extractAllToAsync: (
    targetPath: string,
    overwrite?: boolean,
    keepOriginalPermission?: 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 keepOriginalPermission

      The file will be set as the permission from the entry 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,
    keepOriginalPermission?: boolean,
    outFileName?: string
    ) => 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.

      Parameter keepOriginalPermission

      The file will be set as the permission from the entry if this is true. Default: false.

      Parameter outFileName

      String If set will override the filename of the extracted file (Only works if the entry is a file) Boolean

    method forEach

    forEach: (callback: (entry: AdmZip.IZipEntry) => void) => void;
    • Loop through each entry in the ZIP

      Parameter callback

      The callback that receives each individual entry

    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 getEntryCount

    getEntryCount: () => number;
    • Returns the number of entries in the ZIP The amount of entries in the ZIP

    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) => void,
    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,
    pass?: string | Buffer
    ) => Buffer | null;
    • Extracts the given entry from the archive and returns the content as a Buffer object

      Parameter entry

      ZipEntry object or String with the full path of the entry

      Parameter pass

      Password used for decrypting the file Buffer or Null in case of error

    method readFileAsync

    readFileAsync: (
    entry: string | AdmZip.IZipEntry,
    callback: (data: Buffer | null, err: string) => void
    ) => 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: (password?: string | Buffer) => boolean;
    • Test the archive

      Parameter password

      The password for the archive

    method toBuffer

    toBuffer: {
    (): Buffer;
    (
    onSuccess: (buffer: Buffer) => 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 toBufferPromise

    toBufferPromise: () => Promise<Buffer>;
    • Asynchronously convert the promise to a Buffer

    method updateFile

    updateFile: (entry: string | AdmZip.IZipEntry, content: Buffer) => 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.

    method writeZipPromise

    writeZipPromise: (
    targetFileName?: string,
    props?: { overwrite?: boolean; perm?: number }
    ) => Promise<boolean>;
    • 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: () => Buffer;

                                                                  method entryHeaderToBinary

                                                                  entryHeaderToBinary: () => Buffer;

                                                                    method loadDataHeaderFromBinary

                                                                    loadDataHeaderFromBinary: (data: Buffer) => void;

                                                                      method loadFromBinary

                                                                      loadFromBinary: (data: Buffer) => void;

                                                                        method toString

                                                                        toString: () => string;

                                                                          interface InitOptions

                                                                          interface InitOptions {}

                                                                            property fs

                                                                            fs: null | typeof FS;

                                                                              property method

                                                                              method: (typeof Constants)[keyof typeof Constants] | number;

                                                                                property noSort

                                                                                noSort: boolean;

                                                                                  property readEntries

                                                                                  readEntries: boolean;

                                                                                    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: () => Buffer;
                                                                                          • Retrieve the compressed data for this entry. Note that this may trigger compression if any properties were modified.

                                                                                          method getCompressedDataAsync

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

                                                                                          method getData

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

                                                                                          method getDataAsync

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

                                                                                          method packHeader

                                                                                          packHeader: () => Buffer;
                                                                                          • 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>