// Type definitions for pizzip 3.0
// Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pizzip/pizzip-tests.ts
///
declare class PizZip {
static default: typeof PizZip;
/**
* If the browser supports them, PizZip can take advantage of some "new" features : ArrayBuffer, Blob, Uint8Array.
* To know if PizZip can use them, you can check the PizZip.support object.
*/
static support: {
/**
* true if PizZip can read and generate ArrayBuffer, false otherwise.
*/
arraybuffer: boolean;
/**
* true if PizZip can read and generate Uint8Array, false otherwise.
*/
uint8array: boolean;
/**
* true if PizZip can read and generate Blob, false otherwise.
*/
blob: boolean;
/**
* true if PizZip can read and generate nodejs Buffer, false otherwise.
*/
nodebuffer: boolean;
};
/**
* the ZipObjects inside the zip with the name as key.
*/
files: { [key: string]: PizZip.ZipObject };
/**
* the comment of the zip file.
*/
comment: string;
constructor();
/**
* Specifying data & options is a shortcut for new PizZip().load(data, options);
*
* @param data the zip file
* @param options the options to load the zip file
*/
// tslint:disable-next-line unified-signatures new (undefined, {options}) is not an acceptable input
constructor(data: PizZip.LoadData, options?: PizZip.LoadOptions);
/**
* Read an existing zip and merge the data in the current PizZip object at the current folder level.
* This technique has some limitations, see https://github.com/open-xml-templating/pizzip/blob/master/documentation/limitations.md
* You shouldn't update the data given to this method : it is kept as it so any update will impact the stored data.
* Throws an exception if the loaded data is not valid zip data or if it uses features (multi volume, password protected, etc).
* @param data the zip file
* @param options the options to load the zip file
*/
load(data: PizZip.LoadData, options?: PizZip.LoadOptions): this;
/**
* Add (or update) a file to the zip file.
* You shouldn't update the data given to this method : it is kept as it so any update will impact the stored data.
* Throws an exception if the data is not in a supported format.
* @param name the name of the file. You can specify folders in the name : the folder separator is a forward slash ("/").
* @param data the content of the file.
* @param options the options.
*/
file(name: string, data: PizZip.Data, options?: PizZip.FileOptions): this;
/**
* Get a file with the specified name. You can specify folders in the name : the folder separator is a forward slash ("/").
* @param name the name of the file.
*/
file(name: string): PizZip.ZipObject | null;
/**
* Search a file in the current folder and subfolders with a regular expression. The regex is tested against the relative filename.
* @param regex the regex to use.
*/
file(regex: RegExp): PizZip.ZipObject[];
/**
* Filter nested files/folders with the specified function. The predicate must return true if the file should be included, false otherwise.
* @param predicate the predicate to use.
*/
filter(
predicate: (
/**
* the filename and its path, reliatively to the current folder.
*/
relativePath: string,
/**
* the file being tested
*/
file: PizZip.ZipObject,
) => boolean,
): PizZip.ZipObject[];
/**
* Create a directory if it doesn't exist, return a new PizZip object with the new folder as root.
* @param name the name of the directory.
*/
folder(name: string): this;
/**
* Search a subdirectory in the current directory with a regular expression. The regex is tested against the relative path.
* @param regex the regex to use.
*/
folder(regex: RegExp): PizZip.ZipObject[];
/**
* Generates the complete zip file.
* Throws an exception if the asked type is not available in the browser,
* see https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/support.md
* @param options the options to generate the zip file
*/
generate(options?: PizZip.GenerateOptions & { type?: 'string' | 'base64' | undefined }): string;
generate(options: PizZip.GenerateOptions & { type: 'blob' }): Blob;
generate(options: PizZip.GenerateOptions & { type: 'nodebuffer' }): Buffer;
generate(options: PizZip.GenerateOptions & { type: 'arraybuffer' }): ArrayBuffer;
generate(options: PizZip.GenerateOptions & { type: 'uint8array' }): Uint8Array;
/**
* Delete a file or folder (recursively).
* @param name the name of the file/folder to delete.
*/
remove(name: string): this;
}
declare namespace PizZip {
type Compression = 'STORE' | 'DEFLATE';
type Data = string | ArrayBuffer | Uint8Array | Buffer;
type LoadData = Data | number[];
interface ZipObject {
/**
* the absolute path of the file
*/
name: string;
/**
* true if this is a directory
*/
dir: boolean;
/**
* the last modification date
*/
date: Date;
/**
* the comment for this file
*/
comment: string;
/**
* The UNIX permissions of the file, if any. Also accepts a string representing the octal value : "644", "755", etc. On nodejs you can use the mode attribute of nodejs' fs.Stats.
*/
unixPermissions: number | string;
/**
* The DOS permissions of the file, if any.
*/
dosPermissions: number;
/**
* the options of the file.
*/
options: {
/**
* @deprecated
*/
base64: boolean;
/**
* @deprecated
*/
binary: boolean;
/**
* @deprecated use File.dir
*/
dir: boolean;
/**
* @deprecated use File.date
*/
date: Date;
compression: Compression;
};
/**
* the content as an unicode string.
*/
asText(): string;
/**
* the content as binary string.
*/
asBinary(): string;
/**
* need a compatible browser. https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/support.md
*/
asArrayBuffer(): ArrayBuffer;
/**
* need a compatible browser. https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/support.md
*/
asUint8Array(): Uint8Array;
/**
* need nodejs. https://github.com/open-xml-templating/pizzip/blob/master/documentation/api_pizzip/support.md
*/
asNodeBuffer(): Buffer;
}
interface LoadOptions {
/**
* set to true if the data is base64 encoded, false for binary.
*
* @default false
*/
base64?: boolean | undefined;
/**
* set to true if the read data should be checked against its CRC32.
*
* @default false
*/
checkCRC32?: boolean | undefined;
/**
* set to true if (and only if) the input is a string and has already been prepared with a 0xFF mask.
*
* @default false
*/
optimizedBinaryString?: boolean | undefined;
/**
* set to true to create folders in the file path automatically. Leaving it false will result in only virtual folders
* (i.e. folders that merely represent part of the file path) being created.
*
* @default false
*/
createFolders?: boolean | undefined;
/**
* the function to decode the file name / comment. Decodes from UTF-8 by default.
* A zip file has a flag to say if the filename and comment are encoded with UTF-8.
* If it's not set, PizZip has no way to know the encoding used. It usually is the default encoding of the operating system.
* The function takes the bytes array (Uint8Array or Array) and returns the decoded string.
*/
decodeFileName?(bytes: Uint8Array | number[]): string;
}
interface FileOptions {
/**
* set to `true` if the data is base64 encoded. For example image data from a `