forked from gildas-lormeau/zip.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
291 lines (245 loc) · 10 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
declare module "@zip.js/zip.js" {
export function configure(configuration: ConfigurationOptions): void;
global {
interface FileSystemEntry { }
}
interface ConfigurationOptions {
useWebWorkers?: boolean;
maxWorkers?: number;
terminateWorkerTimeout?: number;
workerScripts?: {
deflate?: string[];
inflate?: string[];
};
chunkSize?: number;
Deflate?: Codec;
Inflate?: Codec;
}
export function initShimAsyncCodec(constructor: object, constructorOptions?: any): { Deflate: Codec, Inflate: Codec };
export function terminateWorkers(): void;
export interface Codec {
append(data: Uint8Array): Promise<Uint8Array>;
flush(): Promise<Uint8Array>;
}
export function getMimeType(fileExtension: string): string;
export class Stream {
public size: number;
public init(): Promise<void>;
}
export class Reader extends Stream {
public readUint8Array(index: number, length: number): Promise<Uint8Array>;
}
export class TextReader extends Reader {
constructor(text: string);
}
export class BlobReader extends Reader {
constructor(blob: Blob);
}
export class Data64URIReader extends Reader {
constructor(dataURI: string);
}
export class Uint8ArrayReader extends Reader {
constructor(array: Uint8Array);
}
export class HttpReader extends Reader {
constructor(url: string, options?: HttpOptions);
}
export class HttpRangeReader extends Reader {
constructor(url: string, options?: HttpRangeOptions);
}
interface HttpOptions extends HttpRangeOptions {
useRangeHeader?: boolean;
preventHeadRequest?: boolean;
}
interface HttpRangeOptions {
forceRangeRequests?: boolean;
useXHR?: boolean;
headers?: Iterable<[string, string]> | Object;
}
export class Writer extends Stream {
public writeUint8Array(array: Uint8Array): Promise<void>;
}
export class TextWriter extends Writer {
constructor(encoding?: string);
public getData(): Promise<string>;
}
export class BlobWriter extends Writer {
constructor(mimeString?: string);
public getData(): Blob;
}
export class Data64URIWriter extends Writer {
constructor(mimeString?: string);
public getData(): string;
}
export class Uint8ArrayWriter extends Writer {
constructor();
public getData(): Uint8Array;
}
export class ZipReader {
constructor(reader: Reader, options?: ZipReaderConstructorOptions);
getEntries(options?: ZipReaderGetEntriesOptions): Promise<Entry[]>;
close(): Promise<any>;
}
type ZipReaderConstructorOptions = ZipReaderOptions & GetEntriesOptions;
type ZipReaderGetEntriesOptions = EntryOnprogressOption & GetEntriesOptions;
interface ZipReaderOptions {
checkSignature?: boolean;
password?: string;
useWebWorkers?: boolean;
signal?: AbortSignal;
}
interface GetEntriesOptions {
filenameEncoding?: string;
commentEncoding?: string;
}
export interface Entry {
offset?: number;
filename: string;
rawFilename: Uint8Array;
filenameUTF8: boolean;
directory: boolean;
encrypted: boolean;
compressedSize: number;
uncompressedSize: number;
lastModDate: Date;
lastAccessDate?: Date;
creationDate?: Date;
rawLastModDate: number;
rawLastAccessDate?: Date;
rawCreationDate?: Date;
comment: string;
rawComment: Uint8Array;
commentUTF8: boolean;
signature: Uint8Array;
extraField?: Map<number, Uint8Array>;
rawExtraField: Uint8Array;
zip64: boolean;
version: number;
versionMadeBy: number;
msDosCompatible: boolean;
internalFileAttribute: number;
externalFileAttribute: number;
getData?(writer: Writer, options?: EntryGetDataOptions): Promise<any>;
}
type EntryGetDataOptions = EntryDataOnprogressOption & ZipReaderOptions;
export class ZipWriter {
readonly hasCorruptedEntries?: boolean;
constructor(writer: Writer, options?: ZipWriterConstructorOptions);
public add(name: string, reader: Reader | null, options?: ZipWriterAddDataOptions): Promise<Entry>;
public close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<any>;
}
type ZipWriterAddDataOptions = EntryDataOnprogressOption & AddDataOptions & ZipWriterConstructorOptions;
type ZipWriterCloseOptions = EntryOnprogressOption & CloseOptions;
interface ZipWriterConstructorOptions {
zip64?: boolean;
level?: number;
bufferedWrite?: boolean;
keepOrder?: boolean;
version?: number;
password?: string;
encryptionStrength?: number;
zipCrypto?: boolean;
useWebWorkers?: boolean;
dataDescriptor?: boolean;
dataDescriptorSignature?: boolean;
signal?: AbortSignal;
lastModDate?: Date;
lastAccessDate?: Date;
creationDate?: Date;
extendedTimestamp?: boolean;
msDosCompatible?: boolean;
internalFileAttribute?: number;
externalFileAttribute?: number;
}
interface AddDataOptions {
directory?: boolean;
comment?: string;
extraField?: Map<number, Uint8Array>;
}
interface CloseOptions {
zip64?: boolean;
}
interface EntryDataOnprogressOption {
onprogress?: (progress: number, total: number) => void;
}
interface EntryOnprogressOption {
onprogress?: (progress: number, total: number, entry: Entry) => void;
}
export interface ZipEntry {
name: string;
data?: Entry;
id: number;
parent?: ZipEntry;
children: ZipEntry[];
uncompressedSize: number;
getFullname(): string;
getRelativeName(ancestor: ZipDirectoryEntry): string;
isDescendantOf(ancestor: ZipDirectoryEntry): boolean;
}
export interface ZipFileEntry extends ZipEntry {
reader: Reader;
writer: Writer;
getText(encoding?: string, options?: EntryGetDataOptions): Promise<string>;
getBlob(mimeType?: string, options?: EntryGetDataOptions): Promise<Blob>;
getData64URI(mimeType?: string, options?: EntryGetDataOptions): Promise<string>;
getUint8Array(options?: EntryGetDataOptions): Promise<Uint8Array>;
getData(writer: Writer, options?: EntryGetDataOptions): Promise<any>;
replaceBlob(blob: Blob): void;
replaceText(text: String): void;
replaceData64URI(dataURI: String): void;
replaceUint8Array(array: Uint8Array): void;
}
interface ExportOptions {
relativePath?: boolean;
}
export interface ZipDirectoryEntry extends ZipEntry {
getChildByName(name: string): ZipEntry;
addDirectory(name: string): ZipDirectoryEntry;
addText(name: string, text: string): ZipFileEntry;
addBlob(name: string, blob: Blob): ZipFileEntry;
addData64URI(name: string, dataURI: string): ZipFileEntry;
addUint8Array(name: string, array: Uint8Array): ZipFileEntry;
addHttpContent(name: string, url: string, options?: HttpOptions): ZipFileEntry;
addFileSystemEntry(fileSystemEntry: FileSystemEntry): Promise<ZipEntry>;
importBlob(blob: Blob, options?: ZipReaderConstructorOptions): Promise<void>;
importData64URI(dataURI: string, options?: ZipReaderConstructorOptions): Promise<void>;
importUint8Array(array: Uint8Array, options?: ZipReaderConstructorOptions): Promise<void>;
importHttpContent(url: string, options?: ZipDirectoryEntryImportHttpOptions): Promise<void>;
exportBlob(options?: ZipDirectoryEntryExportOptions): Promise<Blob>;
exportData64URI(options?: ZipDirectoryEntryExportOptions): Promise<string>;
exportUint8Array(options?: ZipDirectoryEntryExportOptions): Promise<Uint8Array>;
}
type ZipDirectoryEntryImportHttpOptions = ZipReaderConstructorOptions & HttpOptions;
type ZipDirectoryEntryExportOptions = EntryDataOnprogressOption & ExportOptions & ZipWriterConstructorOptions;
export interface FS extends ZipDirectoryEntry {
root: ZipDirectoryEntry;
remove(entry: ZipEntry): void;
move(entry: ZipEntry, destination: ZipDirectoryEntry): void;
find(fullname: string): ZipEntry;
getById(id: number): ZipEntry;
}
export const fs: { FS: FS, ZipDirectoryEntry: ZipDirectoryEntry, ZipFileEntry: ZipFileEntry };
export const ERR_HTTP_RANGE: string;
export const ERR_BAD_FORMAT: string;
export const ERR_EOCDR_NOT_FOUND: string;
export const ERR_EOCDR_ZIP64_NOT_FOUND: string;
export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
export const ERR_ENCRYPTED: string;
export const ERR_UNSUPPORTED_ENCRYPTION: string;
export const ERR_UNSUPPORTED_COMPRESSION: string;
export const ERR_INVALID_SIGNATURE: string;
export const ERR_INVALID_PASSWORD: string;
export const ERR_DUPLICATED_NAME: string;
export const ERR_INVALID_COMMENT: string;
export const ERR_INVALID_ENTRY_NAME: string;
export const ERR_INVALID_ENTRY_COMMENT: string;
export const ERR_INVALID_VERSION: string;
export const ERR_INVALID_EXTRAFIELD_TYPE: string;
export const ERR_INVALID_EXTRAFIELD_DATA: string;
export const ERR_INVALID_ENCRYPTION_STRENGTH: string;
export const ERR_UNSUPPORTED_FORMAT: string;
export const ERR_ABORT: string;
}