UNPKG

@appium/support

Version:

Support libs used across Appium packages

122 lines 4.68 kB
import * as yauzl from 'yauzl'; export interface ExtractAllOptions { /** * The encoding to use for extracted file names. * For ZIP archives created on MacOS it is usually expected to be `utf8`. * By default it is autodetected based on the entry metadata and is only needed to be set explicitly * if the particular archive does not comply to the standards, which leads to corrupted file names * after extraction. Only applicable if system unzip binary is NOT being used. */ fileNamesEncoding?: BufferEncoding; /** * If true, attempt to use system unzip; if this fails, * fallback to the JS unzip implementation. */ useSystemUnzip?: boolean; } /** * Extract zipfile to a directory * * @param zipFilePath The full path to the source ZIP file * @param destDir The full path to the destination folder * @param opts Extraction options */ export declare function extractAllTo(zipFilePath: string, destDir: string, opts?: ExtractAllOptions): Promise<void>; /** * Extract a single zip entry to a directory * * @private * @param zipFile The source ZIP stream * @param entry The entry instance * @param destDir The full path to the destination folder */ export declare function _extractEntryTo(zipFile: yauzl.ZipFile, entry: yauzl.Entry, destDir: string): Promise<void>; export interface ZipEntry { /** The actual entry instance */ entry: yauzl.Entry; /** * Async function which accepts the destination folder path * and extracts this entry into it. */ extractEntryTo: (destDir: string) => Promise<void>; } /** * Get entries for a zip folder * * @param zipFilePath The full path to the source ZIP file * @param onEntry Callback when entry is read. * The callback is expected to accept one argument of ZipEntry type. * The iteration through the source zip file will be terminated as soon as * the result of this function equals to `false`. */ export declare function readEntries(zipFilePath: string, onEntry: (entry: ZipEntry) => boolean | void | Promise<boolean | void>): Promise<void>; export interface ZipOptions { /** Whether to encode the resulting archive to a base64-encoded string */ encodeToBase64?: boolean; /** Whether to log the actual archiver performance */ isMetered?: boolean; /** * The maximum size of the resulting archive in bytes. * This is set to 1GB by default, because Appium limits the maximum HTTP body size to 1GB. * Also, the NodeJS heap size must be enough to keep the resulting object * (usually this size is limited to 1.4 GB) */ maxSize?: number; /** * The compression level. * The maximum level is 9 (the best compression, worst performance). * The minimum compression level is 0 (no compression). */ level?: number; } /** * Converts contents of local directory to an in-memory .zip buffer * * @param srcPath The full path to the folder or file being zipped * @param opts Zipping options * @returns Zipped (and encoded if `encodeToBase64` is truthy) * content of the source path as memory buffer * @throws {Error} if there was an error while reading the source * or the source is too big */ export declare function toInMemoryZip(srcPath: string, opts?: ZipOptions): Promise<Buffer>; /** * Verifies whether the given file is a valid ZIP archive * * @param filePath - Full path to the file * @throws {Error} If the file does not exist or is not a valid ZIP archive */ export declare function assertValidZip(filePath: string): Promise<boolean>; export interface ZipCompressionOptions { /** * Compression level in range 0..9 * (greater numbers mean better compression, but longer processing time) */ level?: number; } export interface ZipSourceOptions { /** GLOB pattern for compression */ pattern?: string; /** The source root folder (the parent folder of the destination file by default) */ cwd?: string; /** The list of ignored patterns */ ignore?: string[]; } /** * Creates an archive based on the given glob pattern * * @param dstPath - The resulting archive path * @param src - Source options * @param opts - Compression options * @throws {Error} If there was an error while creating the archive */ export declare function toArchive(dstPath: string, src?: ZipSourceOptions, opts?: ZipCompressionOptions): Promise<void>; declare const _default: { extractAllTo: typeof extractAllTo; readEntries: typeof readEntries; toInMemoryZip: typeof toInMemoryZip; assertValidZip: typeof assertValidZip; toArchive: typeof toArchive; }; export default _default; //# sourceMappingURL=zip.d.ts.map