UNPKG

4.29 kBTypeScriptView Raw
1/// <reference types="node" />
2
3declare namespace StreamZip {
4 interface StreamZipOptions {
5 /**
6 * File to read
7 * @default undefined
8 */
9 file?: string;
10
11 /**
12 * Alternatively, you can pass fd here
13 * @default undefined
14 */
15 fd?: number;
16
17 /**
18 * You will be able to work with entries inside zip archive,
19 * otherwise the only way to access them is entry event
20 * @default true
21 */
22 storeEntries?: boolean;
23
24 /**
25 * By default, entry name is checked for malicious characters, like ../ or c:\123,
26 * pass this flag to disable validation error
27 * @default false
28 */
29 skipEntryNameValidation?: boolean;
30
31 /**
32 * Filesystem read chunk size
33 * @default automatic based on file size
34 */
35 chunkSize?: number;
36 }
37
38 interface ZipEntry {
39 /**
40 * file name
41 */
42 name: string;
43
44 /**
45 * true if it's a directory entry
46 */
47 isDirectory: boolean;
48
49 /**
50 * true if it's a file entry, see also isDirectory
51 */
52 isFile: boolean;
53
54 /**
55 * file comment
56 */
57 comment: string;
58
59 /**
60 * if the file is encrypted
61 */
62 encrypted: boolean;
63
64 /**
65 * version made by
66 */
67 verMade: number;
68
69 /**
70 * version needed to extract
71 */
72 version: number;
73
74 /**
75 * encrypt, decrypt flags
76 */
77 flags: number;
78
79 /**
80 * compression method
81 */
82 method: number;
83
84 /**
85 * modification time
86 */
87 time: number;
88
89 /**
90 * uncompressed file crc-32 value
91 */
92 crc: number;
93
94 /**
95 * compressed size
96 */
97 compressedSize: number;
98
99 /**
100 * uncompressed size
101 */
102 size: number;
103
104 /**
105 * volume number start
106 */
107 diskStart: number;
108
109 /**
110 * internal file attributes
111 */
112 inattr: number;
113
114 /**
115 * external file attributes
116 */
117 attr: number;
118
119 /**
120 * LOC header offset
121 */
122 offset: number;
123 }
124}
125
126type StreamZipOptions = StreamZip.StreamZipOptions;
127type ZipEntry = StreamZip.ZipEntry;
128
129declare class StreamZipAsync {
130 constructor(config: StreamZipOptions);
131
132 entriesCount: Promise<number>;
133 comment: Promise<string>;
134
135 entry(name: string): Promise<ZipEntry | undefined>;
136 entries(name: string): Promise<{ [name: string]: ZipEntry }>;
137 entryData(entry: string | ZipEntry): Promise<Buffer>;
138 stream(entry: string | ZipEntry): Promise<NodeJS.ReadableStream>;
139 extract(entry: string | ZipEntry | null, outPath: string): Promise<number | undefined>;
140
141 on(event: 'entry', handler: (entry: ZipEntry) => void): void;
142 on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
143
144 close(): Promise<void>;
145}
146
147declare class StreamZip {
148 constructor(config: StreamZipOptions);
149
150 /**
151 * number of entries in the archive
152 */
153 entriesCount: number;
154
155 /**
156 * archive comment
157 */
158 comment: string;
159
160 on(event: 'error', handler: (error: any) => void): void;
161 on(event: 'entry', handler: (entry: ZipEntry) => void): void;
162 on(event: 'ready', handler: () => void): void;
163 on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void;
164
165 entry(name: string): ZipEntry | undefined;
166
167 entries(): { [name: string]: ZipEntry };
168
169 stream(
170 entry: string | ZipEntry,
171 callback: (err: any | null, stream?: NodeJS.ReadableStream) => void
172 ): void;
173
174 entryDataSync(entry: string | ZipEntry): Buffer;
175
176 openEntry(
177 entry: string | ZipEntry,
178 callback: (err: any | null, entry?: ZipEntry) => void,
179 sync: boolean
180 ): void;
181
182 extract(
183 entry: string | ZipEntry | null,
184 outPath: string,
185 callback: (err?: any, res?: number) => void
186 ): void;
187
188 close(callback?: (err?: any) => void): void;
189
190 static async: typeof StreamZipAsync;
191}
192
193export = StreamZip;