UNPKG

zip-lib

Version:

A zip and unzip library for Node.js.

100 lines (99 loc) 3.06 kB
import { Cancelable } from "./cancelable"; export interface IExtractOptions { /** * If it is `true`, the target directory will be deleted before extraction. * The default value is `false`. */ overwrite?: boolean; /** * Extracts symbolic links as files on Windows. This value is only available on Windows and is ignored on other platforms. * The default value is `true`. * * If `true`, the symlink in the zip will be extracted as a normal file on Windows. * * If `false`, the library will try to extract symlinks as real symlinks on Windows. * This may fail with an `EPERM` error when the current process is not allowed to create symlinks. * * > ⚠**WARNING:** On Windows, creating symbolic links may require administrator privileges, * depending on system policy. If Windows Developer Mode is enabled, non-administrator * processes can usually create symlinks as well. */ symlinkAsFileOnWindows?: boolean; /** * Controls the creation phase of symlinks. * * `true`: Refuses to create any symlink whose target is outside the extraction root. * * `false`: Allows creating external symlinks. **Note:** Subsequent write operations to these * links will still be intercepted by the separate AFWRITE security layer. * * The default value is `false`. */ safeSymlinksOnly?: boolean; /** * Called before an item is extracted. * @param event */ onEntry?: (event: IEntryEvent) => void; } /** * Represents an event fired before an entry is extracted. */ export interface IEntryEvent { /** * Entry name. */ readonly entryName: string; /** * Total number of entries. */ readonly entryCount: number; /** * Prevents the current entry from being extracted. */ preventDefault(): void; } /** * Extract the zip file. */ export declare class Unzip extends Cancelable { private options?; /** * */ constructor(options?: IExtractOptions | undefined); private zipFile; private token; /** * Extract the zip buffer to the specified location. * @param zipBuffer * @param targetFolder */ extract(zipBuffer: Buffer, targetFolder: string): Promise<void>; /** * Extract the zip file to the specified location. * @param zipFile * @param targetFolder */ extract(zipFile: string, targetFolder: string): Promise<void>; private prepareExtraction; private processEntries; private handleZipEntry; /** * Cancel extraction. * If the cancel method is called after the extract is complete, nothing will happen. */ cancel(): void; private closeZip; private openZip; private handleEntry; private openZipFileStream; private extractEntry; private writeEntryToFile; private readStreamContent; private modeFromEntry; private createSymlink; private isOverwrite; private onEntryCallback; private symlinkToFile; }