adm-zip
- Version 0.6.0
- Published
- 140 kB
- No dependencies
- MIT license
Install
npm i adm-zipyarn add adm-zippnpm add adm-zipOverview
Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk
Index
Classes
AdmZip
- addFile()
- addLocalFile()
- addLocalFileAsync()
- addLocalFolder()
- addLocalFolderAsync()
- addLocalFolderAsync2()
- addLocalFolderPromise()
- addZipComment()
- addZipEntryComment()
- childCount()
- deleteEntry()
- deleteFile()
- extractAllTo()
- extractAllToAsync()
- extractEntryTo()
- forEach()
- getEntries()
- getEntry()
- getEntryCount()
- getZipComment()
- getZipEntryComment()
- readAsText()
- readAsTextAsync()
- readFile()
- readFileAsync()
- test()
- toBuffer()
- toBufferPromise()
- updateFile()
- writeZip()
- writeZipPromise()
Interfaces
IZipEntryHeader
- attr
- centralHeaderSize
- centralHeaderToBinary()
- commentLength
- compressedSize
- crc
- diskNumStart
- encrypted
- extraLength
- extraLocalLength
- fileAttr
- fileNameLength
- flags
- flags_desc
- flags_efs
- inAttr
- loadFromBinary()
- loadLocalHeaderFromBinary()
- localHeader
- localHeaderToBinary()
- made
- method
- offset
- realDataOffset
- size
- time
- timeHighByte
- timeval
- toJSON()
- toString()
- version
Type Aliases
Classes
class AdmZip
class AdmZip {}constructor
constructor(fileNameOrRawData?: any, options?: Partial<AdmZip.InitOptions>);Parameter fileNameOrRawData
Path to a zip file, a Buffer with zip data, or an options object.
Parameter options
Additional options.
constructor
constructor(options?: Partial<AdmZip.InitOptions>);method addFile
addFile: ( entryName: string, content: Buffer | string, comment?: string, attr?: number | Stats) => AdmZip.IZipEntry;Create an entry from in-memory content. For a directory,
entryNamemust end in/andcontentshould be an empty buffer.Parameter attr
Unix permission bits as a number, or a filesystem
Statsobject.
method addLocalFile
addLocalFile: ( localPath: string, zipPath?: string, zipName?: string, comment?: string) => void;Add a file from disk to the archive.
method addLocalFileAsync
addLocalFileAsync: ( options: | string | { localPath: string; zipPath?: string; zipName?: string; comment?: string; }, callback: (err: Error | undefined, done: boolean) => void) => void;Asynchronously add a file from disk to the archive.
method addLocalFolder
addLocalFolder: ( localPath: string, zipPath?: string, filter?: AdmZip.EntryFilter) => void;Add a folder and all of its nested files/directories to the archive.
method addLocalFolderAsync
addLocalFolderAsync: ( localPath: string, callback: (success?: boolean, err?: string) => void, zipPath?: string, filter?: AdmZip.EntryFilter) => void;Asynchronously add a folder and its contents to the archive.
method addLocalFolderAsync2
addLocalFolderAsync2: ( options: | string | { localPath: string; zipPath?: string; filter?: AdmZip.EntryFilter; namefix?: 'latin1' | ((name: string) => string); }, callback: (err: Error | undefined, done?: boolean) => void) => void;Asynchronously add a folder and its contents to the archive.
method addLocalFolderPromise
addLocalFolderPromise: ( localPath: string, props?: { zipPath?: string; filter?: AdmZip.EntryFilter; namefix?: 'latin1' | ((name: string) => string); }) => Promise<void>;Promise-returning variant of
addLocalFolderAsync2.
method addZipComment
addZipComment: (comment: string) => void;Set the archive-level comment.
method addZipEntryComment
addZipEntryComment: (entry: string | AdmZip.IZipEntry, comment: string) => void;Set the comment of a single entry.
method childCount
childCount: (entry: string | AdmZip.IZipEntry) => number;Number of child entries for a directory entry (0 for files).
method deleteEntry
deleteEntry: (entry: string | AdmZip.IZipEntry) => void;Remove a single entry.
method deleteFile
deleteFile: (entry: string | AdmZip.IZipEntry, withSubfolders?: boolean) => void;Remove an entry (and, for a directory, optionally its children).
method extractAllTo
extractAllTo: ( targetPath: string, overwrite?: boolean, keepOriginalPermission?: boolean, pass?: string | Buffer) => void;Extract the entire archive to disk.
method extractAllToAsync
extractAllToAsync: { ( targetPath: string, overwrite?: boolean, keepOriginalPermission?: boolean ): Promise<void>; ( targetPath: string, overwrite: boolean, keepOriginalPermission: boolean, callback: (error?: Error) => void ): void;};Asynchronously extract the entire archive to disk. Returns a Promise when no callback is given.
method extractEntryTo
extractEntryTo: ( entry: string | AdmZip.IZipEntry, targetPath: string, maintainEntryPath?: boolean, overwrite?: boolean, keepOriginalPermission?: boolean, outFileName?: string) => boolean;Extract a single entry (or a directory subtree) to disk. Returns success.
method forEach
forEach: (callback: (entry: AdmZip.IZipEntry) => void) => void;Iterate every entry.
method getEntries
getEntries: (password?: string) => AdmZip.IZipEntry[];All entries in the archive.
method getEntry
getEntry: (name: string) => AdmZip.IZipEntry | null;Look up a single entry by name, or null if absent.
method getEntryCount
getEntryCount: () => number;Number of entries in the archive.
method getZipComment
getZipComment: () => string;Get the archive-level comment.
method getZipEntryComment
getZipEntryComment: (entry: string | AdmZip.IZipEntry) => string;Get the comment of a single entry.
method readAsText
readAsText: (entry: string | AdmZip.IZipEntry, encoding?: string) => string;Extract an entry and return its content as text (default encoding utf8).
method readAsTextAsync
readAsTextAsync: ( entry: string | AdmZip.IZipEntry, callback: (data: string, err?: string) => void, encoding?: string) => void;Asynchronously extract an entry's content as text.
method readFile
readFile: ( entry: string | AdmZip.IZipEntry, pass?: string | Buffer) => Buffer | null;Extract an entry and return its content as a Buffer, or null if not found.
method readFileAsync
readFileAsync: ( entry: string | AdmZip.IZipEntry, callback: (data: Buffer | null, err?: string) => void) => void;Asynchronously extract an entry's content.
method test
test: (pass?: string | Buffer) => boolean;Verify every entry decompresses with a valid CRC.
method toBuffer
toBuffer: { (): Buffer; ( onSuccess: (buffer: Buffer) => void, onFail?: (error: unknown) => void, onItemStart?: (name: string) => void, onItemEnd?: (name: string) => void ): null;};Serialize the archive to a Buffer. With callbacks it runs asynchronously and returns null.
method toBufferPromise
toBufferPromise: () => Promise<Buffer>;Serialize the archive to a Buffer asynchronously.
method updateFile
updateFile: (entry: string | AdmZip.IZipEntry, content: Buffer) => void;Replace the content of an existing entry.
method writeZip
writeZip: ( targetFileName?: string, callback?: (error: Error | null) => void) => void;Write the archive to disk (uses the constructor filename if none supplied).
method writeZipPromise
writeZipPromise: ( targetFileName?: string, props?: { overwrite?: boolean; perm?: number }) => Promise<void>;Promise-returning variant of
writeZip.
Interfaces
interface InitOptions
interface InitOptions {}Options accepted by the AdmZip constructor.
property decoder
decoder?: ZipTextDecoder;Custom text encoder/decoder for entry names (e.g. to support MBCS via iconv-lite).
property filename
filename?: string;Filename used by
writeZip/writeZipPromisewhen none is supplied.
property fs
fs: unknown | null;Custom filesystem implementation (e.g. Electron's
original-fs).
property input
input?: Buffer;Raw zip buffer to load (alternative to passing a Buffer as the first argument).
property method
method: number;Default compression method for new entries (see Constants: STORED = 0, DEFLATED = 8).
property noSort
noSort: boolean;If true, disables sorting of the entries by name.
property readEntries
readEntries: boolean;Read all entries during load (slower initial load, avoids lazy parsing later).
interface IZipEntry
interface IZipEntry {}A single file or directory inside the archive.
property attr
attr: number;MS-DOS / unix packed attribute value.
property comment
comment: string;Entry comment.
property efs
readonly efs: boolean;Whether the name uses UTF-8 (EFS) encoding.
property entryName
entryName: string;Full path of the entry within the archive.
property extra
extra: Buffer;Extra field bytes.
property header
header: IZipEntryHeader;property isDirectory
readonly isDirectory: boolean;property name
readonly name: string;The base name of the entry (last path segment).
property rawEntryName
readonly rawEntryName: Buffer;Raw (un-decoded) entry name bytes.
method getCompressedData
getCompressedData: () => Buffer;method getCompressedDataAsync
getCompressedDataAsync: (callback: (data: Buffer) => void) => void;method getData
getData: (pass?: string | Buffer) => Buffer;Decompress and return the entry content. Throws on a bad CRC.
method getDataAsync
getDataAsync: ( callback: (data: Buffer, err?: string) => void, pass?: string | Buffer) => void;method packCentralHeader
packCentralHeader: () => Buffer;method packLocalHeader
packLocalHeader: () => Buffer;method setData
setData: (value: string | Buffer) => void;method toJSON
toJSON: () => object;method toString
toString: () => string;interface IZipEntryHeader
interface IZipEntryHeader {}The central-directory / local file header of a single entry.
property attr
attr: number;property centralHeaderSize
readonly centralHeaderSize: number;property commentLength
commentLength: number;property compressedSize
compressedSize: number;property crc
crc: number;property diskNumStart
diskNumStart: number;property encrypted
readonly encrypted: boolean;property extraLength
extraLength: number;property extraLocalLength
extraLocalLength: number;property fileAttr
readonly fileAttr: number;Unix permission bits (e.g. 0o755), derived from
attr.
property fileNameLength
fileNameLength: number;property flags
flags: number;property flags_desc
flags_desc: boolean;property flags_efs
flags_efs: boolean;property inAttr
inAttr: number;property localHeader
readonly localHeader: Record<string, number | boolean>;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 timeHighByte
readonly timeHighByte: number;property timeval
timeval: number;property version
version: number;method centralHeaderToBinary
centralHeaderToBinary: () => Buffer;method loadFromBinary
loadFromBinary: (data: Buffer) => void;method loadLocalHeaderFromBinary
loadLocalHeaderFromBinary: (input: Buffer) => Buffer;method localHeaderToBinary
localHeaderToBinary: () => Buffer;method toJSON
toJSON: () => object;method toString
toString: () => string;interface ZipTextDecoder
interface ZipTextDecoder {}Encoder/decoder used for entry names and comments.
Type Aliases
type EntryFilter
type EntryFilter = RegExp | ((entryPath: string) => boolean);Filter deciding whether an entry is included when adding a local folder.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (5)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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/adm-zip.
- Markdown[](https://www.jsdocs.io/package/adm-zip)
- HTML<a href="https://www.jsdocs.io/package/adm-zip"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4132 ms. - Missing or incorrect documentation? Open an issue for this package.
