1 | /// <reference types="node" />
|
2 |
|
3 | declare 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 |
|
126 | type StreamZipOptions = StreamZip.StreamZipOptions;
|
127 | type ZipEntry = StreamZip.ZipEntry;
|
128 |
|
129 | declare class StreamZip {
|
130 | constructor(config: StreamZipOptions);
|
131 |
|
132 | /**
|
133 | * number of entries in the archive
|
134 | */
|
135 | entriesCount: number
|
136 |
|
137 | /**
|
138 | * archive comment
|
139 | */
|
140 | comment: string
|
141 |
|
142 | on(event: 'error', handler: (error: any) => void): void
|
143 | on(event: 'entry', handler: (entry: ZipEntry) => void): void
|
144 | on(event: 'ready', handler: () => void): void
|
145 | on(event: 'extract', handler: (entry: ZipEntry, outPath: string) => void): void
|
146 |
|
147 | entry(name: string): ZipEntry | undefined
|
148 |
|
149 | entries(): { [name: string]: ZipEntry }
|
150 |
|
151 | stream(entry: string | ZipEntry, callback: (err: any | null, stream?: NodeJS.ReadableStream) => void): void
|
152 |
|
153 | entryDataSync(entry: string | ZipEntry): Buffer
|
154 |
|
155 | openEntry(entry: string | ZipEntry, callback: (err: any | null, entry?: ZipEntry) => void, sync: boolean): void
|
156 |
|
157 | extract(entry: string | ZipEntry | null, outPath: string, callback: (err?: any) => void): void
|
158 |
|
159 | close(callback?: (err?: any) => void): void
|
160 | }
|
161 |
|
162 | export = StreamZip;
|