zip-lib
Version:
A zip and unzip library for Node.js.
87 lines (86 loc) • 2.9 kB
TypeScript
import { Cancelable } from "./cancelable";
export interface IZipOptions {
/**
* Indicates how to handle the given path when it is a symbolic link.
*
* `true`: add the target of the symbolic link to the zip.
*
* `false`: add the symbolic link itself to the zip.
*
* The default value is `false`.
*/
followSymlinks?: boolean;
/**
* Sets the compression level.
*
* `0`: the file data will be stored; otherwise, the file data will be deflated.
*
* The default value is `6`.
*/
compressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
}
/**
* Compress files or folders to a zip file.
*/
export declare class Zip extends Cancelable {
private options?;
/**
*
*/
constructor(options?: IZipOptions | undefined);
private zipFiles;
private zipFolders;
private token;
private activeArchive;
/**
* Adds a file from the file system at `realPath` to the zip file as `metadataPath`.
* @param file
* @param metadataPath Typically, `metadataPath` would be calculated as `path.relative(root, realPath)`.
* A valid metadataPath must not start with "/" or /[A-Za-z]:\//, and must not contain "..".
*/
addFile(file: string, metadataPath?: string): void;
/**
* Adds a folder from the file system at `realPath` to the zip file as `metadataPath`.
* @param folder
* @param metadataPath Typically, `metadataPath` would be calculated as `path.relative(root, realPath)`.
* A valid metadataPath must not start with "/" or /[A-Za-z]:\//, and must not contain "..".
*/
addFolder(folder: string, metadataPath?: string): void;
/**
* Zips the content and returns it as a single Buffer.
*
* @returns A promise that resolves to the zipped Buffer.
*/
archive(): Promise<Buffer>;
/**
* Zips the content and saves it directly to the specified file path.
*
* @param zipFile The absolute or relative path where the .zip file will be created.
* @returns A promise that resolves when the file has been fully written.
*/
archive(zipFile: string): Promise<void>;
private prepareArchive;
private bindArchiveOutput;
private archiveToFile;
private archiveToBuffer;
private createPromiseSettler;
private addQueuedEntries;
/**
* Cancel compression.
* If the cancel method is called after the archive is complete, nothing will happen.
*/
cancel(): void;
private addEntry;
private addFileStream;
private addSymlink;
private walkDir;
private stop;
private followSymlink;
/**
* Retrieves the yazl options based on the current settings.
*
* @returns The yazl options with the specified compression level,
* or undefined if options or compressionLevel are not properly set.
*/
private getYazlOption;
}