UNPKG

4.99 kBTypeScriptView Raw
1// Type definitions for JSZip
2// Project: http://stuk.github.com/jszip/
3// Definitions by: mzeiher <https://github.com/mzeiher>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6interface JSZip {
7 /**
8 * Get a file from the archive
9 *
10 * @param Path relative path to file
11 * @return File matching path, null if no file found
12 */
13 file(path: string): JSZipObject;
14
15 /**
16 * Get files matching a RegExp from archive
17 *
18 * @param path RegExp to match
19 * @return Return all matching files or an empty array
20 */
21 file(path: RegExp): JSZipObject[];
22
23 /**
24 * Add a file to the archive
25 *
26 * @param path Relative path to file
27 * @param content Content of the file
28 * @param options Optional information about the file
29 * @return JSZip object
30 */
31 file(path: string, data: any, options?: JSZipFileOptions): JSZip;
32
33 /**
34 * Return an new JSZip instance with the given folder as root
35 *
36 * @param name Name of the folder
37 * @return New JSZip object with the given folder as root or null
38 */
39 folder(name: string): JSZip;
40
41 /**
42 * Returns new JSZip instances with the matching folders as root
43 *
44 * @param name RegExp to match
45 * @return New array of JSZipFile objects which match the RegExp
46 */
47 folder(name: RegExp): JSZipObject[];
48
49 /**
50 * Get all files wchich match the given filter function
51 *
52 * @param predicate Filter function
53 * @return Array of matched elements
54 */
55 filter(predicate: (relativePath: string, file: JSZipObject) => boolean): JSZipObject[];
56
57 /**
58 * Removes the file or folder from the archive
59 *
60 * @param path Relative path of file or folder
61 * @return Returns the JSZip instance
62 */
63 remove(path: string): JSZip;
64
65 /**
66 * Generates a new archive
67 *
68 * @param options Optional options for the generator
69 * @return The serialized archive
70 */
71 generate(options?: JSZipGeneratorOptions): any;
72
73 /**
74 * Deserialize zip file
75 *
76 * @param data Serialized zip file
77 * @param options Options for deserializing
78 * @return Returns the JSZip instance
79 */
80 load(data: any, options: JSZipLoadOptions): JSZip;
81}
82
83interface JSZipObject {
84 name: string;
85 dir: boolean;
86 date: Date;
87 comment: string;
88 options: JSZipObjectOptions;
89
90 asText(): string;
91 asBinary(): string;
92 asArrayBuffer(): ArrayBuffer;
93 asUint8Array(): Uint8Array;
94 //asNodeBuffer(): Buffer;
95}
96
97interface JSZipFileOptions {
98 base64?: boolean;
99 binary?: boolean;
100 date?: Date;
101 compression?: string;
102 comment?: string;
103 optimizedBinaryString?: boolean;
104 createFolders?: boolean;
105}
106
107interface JSZipObjectOptions {
108 /** deprecated */
109 base64: boolean;
110 /** deprecated */
111 binary: boolean;
112 /** deprecated */
113 dir: boolean;
114 /** deprecated */
115 date: Date;
116 compression: string;
117}
118
119interface JSZipGeneratorOptions {
120 /** deprecated */
121 base64?: boolean;
122 /** DEFLATE or STORE */
123 compression?: string;
124 /** base64 (default), string, uint8array, blob */
125 type?: string;
126 comment?: string;
127}
128
129interface JSZipLoadOptions {
130 base64?: boolean;
131 checkCRC32?: boolean;
132 optimizedBinaryString?: boolean;
133 createFolders?: boolean;
134}
135
136interface JSZipSupport {
137 arraybuffer: boolean;
138 uint8array: boolean;
139 blob: boolean;
140 nodebuffer: boolean;
141}
142
143interface DEFLATE {
144 /** pako.deflateRaw, level:0-9 */
145 compress(input: string, compressionOptions: {level:number}): Uint8Array;
146 compress(input: number[], compressionOptions: {level:number}): Uint8Array;
147 compress(input: Uint8Array, compressionOptions: {level:number}): Uint8Array;
148
149 /** pako.inflateRaw */
150 uncompress(input: string): Uint8Array;
151 uncompress(input: number[]): Uint8Array;
152 uncompress(input: Uint8Array): Uint8Array;
153}
154
155declare var JSZip: {
156 /**
157 * Create JSZip instance
158 */
159 (): JSZip;
160 /**
161 * Create JSZip instance
162 * If no parameters given an empty zip archive will be created
163 *
164 * @param data Serialized zip archive
165 * @param options Description of the serialized zip archive
166 */
167 (data: any, options?: JSZipLoadOptions): JSZip;
168
169 /**
170 * Create JSZip instance
171 */
172 new (): JSZip;
173 /**
174 * Create JSZip instance
175 * If no parameters given an empty zip archive will be created
176 *
177 * @param data Serialized zip archive
178 * @param options Description of the serialized zip archive
179 */
180 new (data: any, options?: JSZipLoadOptions): JSZip;
181
182 prototype: JSZip;
183 support: JSZipSupport;
184 compressions: {
185 DEFLATE: DEFLATE;
186 }
187}
188
189declare module "jszip" {
190 export = JSZip;
191}