[79a0317] | 1 | /**
|
---|
| 2 | * Codes for errors generated within this library
|
---|
| 3 | */
|
---|
| 4 | export declare const FlateErrorCode: {
|
---|
| 5 | readonly UnexpectedEOF: 0;
|
---|
| 6 | readonly InvalidBlockType: 1;
|
---|
| 7 | readonly InvalidLengthLiteral: 2;
|
---|
| 8 | readonly InvalidDistance: 3;
|
---|
| 9 | readonly StreamFinished: 4;
|
---|
| 10 | readonly NoStreamHandler: 5;
|
---|
| 11 | readonly InvalidHeader: 6;
|
---|
| 12 | readonly NoCallback: 7;
|
---|
| 13 | readonly InvalidUTF8: 8;
|
---|
| 14 | readonly ExtraFieldTooLong: 9;
|
---|
| 15 | readonly InvalidDate: 10;
|
---|
| 16 | readonly FilenameTooLong: 11;
|
---|
| 17 | readonly StreamFinishing: 12;
|
---|
| 18 | readonly InvalidZipData: 13;
|
---|
| 19 | readonly UnknownCompressionMethod: 14;
|
---|
| 20 | };
|
---|
| 21 | /**
|
---|
| 22 | * An error generated within this library
|
---|
| 23 | */
|
---|
| 24 | export interface FlateError extends Error {
|
---|
| 25 | /**
|
---|
| 26 | * The code associated with this error
|
---|
| 27 | */
|
---|
| 28 | code: number;
|
---|
| 29 | }
|
---|
| 30 | /**
|
---|
| 31 | * Options for decompressing a DEFLATE stream
|
---|
| 32 | */
|
---|
| 33 | export interface InflateStreamOptions {
|
---|
| 34 | /**
|
---|
| 35 | * The dictionary used to compress the original data. If no dictionary was used during compression, this option has no effect.
|
---|
| 36 | *
|
---|
| 37 | * Supplying the wrong dictionary during decompression usually yields corrupt output or causes an invalid distance error.
|
---|
| 38 | */
|
---|
| 39 | dictionary?: Uint8Array;
|
---|
| 40 | }
|
---|
| 41 | /**
|
---|
| 42 | * Options for decompressing DEFLATE data
|
---|
| 43 | */
|
---|
| 44 | export interface InflateOptions extends InflateStreamOptions {
|
---|
| 45 | /**
|
---|
| 46 | * The buffer into which to write the decompressed data. Saves memory if you know the decompressed size in advance.
|
---|
| 47 | *
|
---|
| 48 | * Note that if the decompression result is larger than the size of this buffer, it will be truncated to fit.
|
---|
| 49 | */
|
---|
| 50 | out?: Uint8Array;
|
---|
| 51 | }
|
---|
| 52 | /**
|
---|
| 53 | * Options for decompressing a GZIP stream
|
---|
| 54 | */
|
---|
| 55 | export interface GunzipStreamOptions extends InflateStreamOptions {
|
---|
| 56 | }
|
---|
| 57 | /**
|
---|
| 58 | * Options for decompressing GZIP data
|
---|
| 59 | */
|
---|
| 60 | export interface GunzipOptions extends InflateStreamOptions {
|
---|
| 61 | /**
|
---|
| 62 | * The buffer into which to write the decompressed data. GZIP already encodes the output size, so providing this doesn't save memory.
|
---|
| 63 | *
|
---|
| 64 | * Note that if the decompression result is larger than the size of this buffer, it will be truncated to fit.
|
---|
| 65 | */
|
---|
| 66 | out?: Uint8Array;
|
---|
| 67 | }
|
---|
| 68 | /**
|
---|
| 69 | * Options for decompressing a Zlib stream
|
---|
| 70 | */
|
---|
| 71 | export interface UnzlibStreamOptions extends InflateStreamOptions {
|
---|
| 72 | }
|
---|
| 73 | /**
|
---|
| 74 | * Options for decompressing Zlib data
|
---|
| 75 | */
|
---|
| 76 | export interface UnzlibOptions extends InflateOptions {
|
---|
| 77 | }
|
---|
| 78 | /**
|
---|
| 79 | * Options for compressing data into a DEFLATE format
|
---|
| 80 | */
|
---|
| 81 | export interface DeflateOptions {
|
---|
| 82 | /**
|
---|
| 83 | * The level of compression to use, ranging from 0-9.
|
---|
| 84 | *
|
---|
| 85 | * 0 will store the data without compression.
|
---|
| 86 | * 1 is fastest but compresses the worst, 9 is slowest but compresses the best.
|
---|
| 87 | * The default level is 6.
|
---|
| 88 | *
|
---|
| 89 | * Typically, binary data benefits much more from higher values than text data.
|
---|
| 90 | * In both cases, higher values usually take disproportionately longer than the reduction in final size that results.
|
---|
| 91 | *
|
---|
| 92 | * For example, a 1 MB text file could:
|
---|
| 93 | * - become 1.01 MB with level 0 in 1ms
|
---|
| 94 | * - become 400 kB with level 1 in 10ms
|
---|
| 95 | * - become 320 kB with level 9 in 100ms
|
---|
| 96 | */
|
---|
| 97 | level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
---|
| 98 | /**
|
---|
| 99 | * The memory level to use, ranging from 0-12. Increasing this increases speed and compression ratio at the cost of memory.
|
---|
| 100 | *
|
---|
| 101 | * Note that this is exponential: while level 0 uses 4 kB, level 4 uses 64 kB, level 8 uses 1 MB, and level 12 uses 16 MB.
|
---|
| 102 | * It is recommended not to lower the value below 4, since that tends to hurt performance.
|
---|
| 103 | * In addition, values above 8 tend to help very little on most data and can even hurt performance.
|
---|
| 104 | *
|
---|
| 105 | * The default value is automatically determined based on the size of the input data.
|
---|
| 106 | */
|
---|
| 107 | mem?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
---|
| 108 | /**
|
---|
| 109 | * A buffer containing common byte sequences in the input data that can be used to significantly improve compression ratios.
|
---|
| 110 | *
|
---|
| 111 | * Dictionaries should be 32kB or smaller and include strings or byte sequences likely to appear in the input.
|
---|
| 112 | * The decompressor must supply the same dictionary as the compressor to extract the original data.
|
---|
| 113 | *
|
---|
| 114 | * Dictionaries only improve aggregate compression ratio when reused across multiple small inputs. They should typically not be used otherwise.
|
---|
| 115 | *
|
---|
| 116 | * Avoid using dictionaries with GZIP and ZIP to maximize software compatibility.
|
---|
| 117 | */
|
---|
| 118 | dictionary?: Uint8Array;
|
---|
| 119 | }
|
---|
| 120 | /**
|
---|
| 121 | * Options for compressing data into a GZIP format
|
---|
| 122 | */
|
---|
| 123 | export interface GzipOptions extends DeflateOptions {
|
---|
| 124 | /**
|
---|
| 125 | * When the file was last modified. Defaults to the current time.
|
---|
| 126 | * Set this to 0 to avoid revealing a modification date entirely.
|
---|
| 127 | */
|
---|
| 128 | mtime?: Date | string | number;
|
---|
| 129 | /**
|
---|
| 130 | * The filename of the data. If the `gunzip` command is used to decompress the data, it will output a file
|
---|
| 131 | * with this name instead of the name of the compressed file.
|
---|
| 132 | */
|
---|
| 133 | filename?: string;
|
---|
| 134 | }
|
---|
| 135 | /**
|
---|
| 136 | * Options for compressing data into a Zlib format
|
---|
| 137 | */
|
---|
| 138 | export interface ZlibOptions extends DeflateOptions {
|
---|
| 139 | }
|
---|
| 140 | /**
|
---|
| 141 | * Handler for data (de)compression streams
|
---|
| 142 | * @param data The data output from the stream processor
|
---|
| 143 | * @param final Whether this is the final block
|
---|
| 144 | */
|
---|
| 145 | export type FlateStreamHandler = (data: Uint8Array, final: boolean) => void;
|
---|
| 146 | /**
|
---|
| 147 | * Handler for asynchronous data (de)compression streams
|
---|
| 148 | * @param err Any error that occurred
|
---|
| 149 | * @param data The data output from the stream processor
|
---|
| 150 | * @param final Whether this is the final block
|
---|
| 151 | */
|
---|
| 152 | export type AsyncFlateStreamHandler = (err: FlateError | null, data: Uint8Array, final: boolean) => void;
|
---|
| 153 | /**
|
---|
| 154 | * Handler for the asynchronous completion of (de)compression for a data chunk
|
---|
| 155 | * @param size The number of bytes that were processed. This is measured in terms of the input
|
---|
| 156 | * (i.e. compressed bytes for decompression, uncompressed bytes for compression.)
|
---|
| 157 | */
|
---|
| 158 | export type AsyncFlateDrainHandler = (size: number) => void;
|
---|
| 159 | /**
|
---|
| 160 | * Callback for asynchronous (de)compression methods
|
---|
| 161 | * @param err Any error that occurred
|
---|
| 162 | * @param data The resulting data. Only present if `err` is null
|
---|
| 163 | */
|
---|
| 164 | export type FlateCallback = (err: FlateError | null, data: Uint8Array) => void;
|
---|
| 165 | interface AsyncOptions {
|
---|
| 166 | /**
|
---|
| 167 | * Whether or not to "consume" the source data. This will make the typed array/buffer you pass in
|
---|
| 168 | * unusable but will increase performance and reduce memory usage.
|
---|
| 169 | */
|
---|
| 170 | consume?: boolean;
|
---|
| 171 | }
|
---|
| 172 | /**
|
---|
| 173 | * Options for compressing data asynchronously into a DEFLATE format
|
---|
| 174 | */
|
---|
| 175 | export interface AsyncDeflateOptions extends DeflateOptions, AsyncOptions {
|
---|
| 176 | }
|
---|
| 177 | /**
|
---|
| 178 | * Options for decompressing DEFLATE data asynchronously
|
---|
| 179 | */
|
---|
| 180 | export interface AsyncInflateOptions extends AsyncOptions, InflateStreamOptions {
|
---|
| 181 | /**
|
---|
| 182 | * The original size of the data. Currently, the asynchronous API disallows
|
---|
| 183 | * writing into a buffer you provide; the best you can do is provide the
|
---|
| 184 | * size in bytes and be given back a new typed array.
|
---|
| 185 | */
|
---|
| 186 | size?: number;
|
---|
| 187 | }
|
---|
| 188 | /**
|
---|
| 189 | * Options for compressing data asynchronously into a GZIP format
|
---|
| 190 | */
|
---|
| 191 | export interface AsyncGzipOptions extends GzipOptions, AsyncOptions {
|
---|
| 192 | }
|
---|
| 193 | /**
|
---|
| 194 | * Options for decompressing GZIP data asynchronously
|
---|
| 195 | */
|
---|
| 196 | export interface AsyncGunzipOptions extends AsyncOptions, InflateStreamOptions {
|
---|
| 197 | }
|
---|
| 198 | /**
|
---|
| 199 | * Options for compressing data asynchronously into a Zlib format
|
---|
| 200 | */
|
---|
| 201 | export interface AsyncZlibOptions extends ZlibOptions, AsyncOptions {
|
---|
| 202 | }
|
---|
| 203 | /**
|
---|
| 204 | * Options for decompressing Zlib data asynchronously
|
---|
| 205 | */
|
---|
| 206 | export interface AsyncUnzlibOptions extends AsyncInflateOptions {
|
---|
| 207 | }
|
---|
| 208 | /**
|
---|
| 209 | * A terminable compression/decompression process
|
---|
| 210 | */
|
---|
| 211 | export interface AsyncTerminable {
|
---|
| 212 | /**
|
---|
| 213 | * Terminates the worker thread immediately. The callback will not be called.
|
---|
| 214 | */
|
---|
| 215 | (): void;
|
---|
| 216 | }
|
---|
| 217 | /**
|
---|
| 218 | * Streaming DEFLATE compression
|
---|
| 219 | */
|
---|
| 220 | export declare class Deflate {
|
---|
| 221 | /**
|
---|
| 222 | * Creates a DEFLATE stream
|
---|
| 223 | * @param opts The compression options
|
---|
| 224 | * @param cb The callback to call whenever data is deflated
|
---|
| 225 | */
|
---|
| 226 | constructor(opts: DeflateOptions, cb?: FlateStreamHandler);
|
---|
| 227 | /**
|
---|
| 228 | * Creates a DEFLATE stream
|
---|
| 229 | * @param cb The callback to call whenever data is deflated
|
---|
| 230 | */
|
---|
| 231 | constructor(cb?: FlateStreamHandler);
|
---|
| 232 | private b;
|
---|
| 233 | private s;
|
---|
| 234 | private o;
|
---|
| 235 | /**
|
---|
| 236 | * The handler to call whenever data is available
|
---|
| 237 | */
|
---|
| 238 | ondata: FlateStreamHandler;
|
---|
| 239 | private p;
|
---|
| 240 | /**
|
---|
| 241 | * Pushes a chunk to be deflated
|
---|
| 242 | * @param chunk The chunk to push
|
---|
| 243 | * @param final Whether this is the last chunk
|
---|
| 244 | */
|
---|
| 245 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 246 | /**
|
---|
| 247 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 248 | * deflated output for small inputs.
|
---|
| 249 | */
|
---|
| 250 | flush(): void;
|
---|
| 251 | }
|
---|
| 252 | /**
|
---|
| 253 | * Asynchronous streaming DEFLATE compression
|
---|
| 254 | */
|
---|
| 255 | export declare class AsyncDeflate {
|
---|
| 256 | /**
|
---|
| 257 | * The handler to call whenever data is available
|
---|
| 258 | */
|
---|
| 259 | ondata: AsyncFlateStreamHandler;
|
---|
| 260 | /**
|
---|
| 261 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 262 | */
|
---|
| 263 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 264 | /**
|
---|
| 265 | * The number of uncompressed bytes buffered in the stream
|
---|
| 266 | */
|
---|
| 267 | queuedSize: number;
|
---|
| 268 | /**
|
---|
| 269 | * Creates an asynchronous DEFLATE stream
|
---|
| 270 | * @param opts The compression options
|
---|
| 271 | * @param cb The callback to call whenever data is deflated
|
---|
| 272 | */
|
---|
| 273 | constructor(opts: DeflateOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 274 | /**
|
---|
| 275 | * Creates an asynchronous DEFLATE stream
|
---|
| 276 | * @param cb The callback to call whenever data is deflated
|
---|
| 277 | */
|
---|
| 278 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 279 | /**
|
---|
| 280 | * Pushes a chunk to be deflated
|
---|
| 281 | * @param chunk The chunk to push
|
---|
| 282 | * @param final Whether this is the last chunk
|
---|
| 283 | */
|
---|
| 284 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 285 | /**
|
---|
| 286 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 287 | * deflated output for small inputs.
|
---|
| 288 | */
|
---|
| 289 | flush(): void;
|
---|
| 290 | /**
|
---|
| 291 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 292 | * push() will silently fail.
|
---|
| 293 | */
|
---|
| 294 | terminate: AsyncTerminable;
|
---|
| 295 | }
|
---|
| 296 | /**
|
---|
| 297 | * Asynchronously compresses data with DEFLATE without any wrapper
|
---|
| 298 | * @param data The data to compress
|
---|
| 299 | * @param opts The compression options
|
---|
| 300 | * @param cb The function to be called upon compression completion
|
---|
| 301 | * @returns A function that can be used to immediately terminate the compression
|
---|
| 302 | */
|
---|
| 303 | export declare function deflate(data: Uint8Array, opts: AsyncDeflateOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 304 | /**
|
---|
| 305 | * Asynchronously compresses data with DEFLATE without any wrapper
|
---|
| 306 | * @param data The data to compress
|
---|
| 307 | * @param cb The function to be called upon compression completion
|
---|
| 308 | */
|
---|
| 309 | export declare function deflate(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 310 | /**
|
---|
| 311 | * Compresses data with DEFLATE without any wrapper
|
---|
| 312 | * @param data The data to compress
|
---|
| 313 | * @param opts The compression options
|
---|
| 314 | * @returns The deflated version of the data
|
---|
| 315 | */
|
---|
| 316 | export declare function deflateSync(data: Uint8Array, opts?: DeflateOptions): Uint8Array;
|
---|
| 317 | /**
|
---|
| 318 | * Streaming DEFLATE decompression
|
---|
| 319 | */
|
---|
| 320 | export declare class Inflate {
|
---|
| 321 | private s;
|
---|
| 322 | private o;
|
---|
| 323 | private p;
|
---|
| 324 | private d;
|
---|
| 325 | /**
|
---|
| 326 | * The handler to call whenever data is available
|
---|
| 327 | */
|
---|
| 328 | ondata: FlateStreamHandler;
|
---|
| 329 | /**
|
---|
| 330 | * Creates a DEFLATE decompression stream
|
---|
| 331 | * @param opts The decompression options
|
---|
| 332 | * @param cb The callback to call whenever data is inflated
|
---|
| 333 | */
|
---|
| 334 | constructor(opts: InflateStreamOptions, cb?: FlateStreamHandler);
|
---|
| 335 | /**
|
---|
| 336 | * Creates a DEFLATE decompression stream
|
---|
| 337 | * @param cb The callback to call whenever data is inflated
|
---|
| 338 | */
|
---|
| 339 | constructor(cb?: FlateStreamHandler);
|
---|
| 340 | private e;
|
---|
| 341 | private c;
|
---|
| 342 | /**
|
---|
| 343 | * Pushes a chunk to be inflated
|
---|
| 344 | * @param chunk The chunk to push
|
---|
| 345 | * @param final Whether this is the final chunk
|
---|
| 346 | */
|
---|
| 347 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 348 | }
|
---|
| 349 | /**
|
---|
| 350 | * Asynchronous streaming DEFLATE decompression
|
---|
| 351 | */
|
---|
| 352 | export declare class AsyncInflate {
|
---|
| 353 | /**
|
---|
| 354 | * The handler to call whenever data is available
|
---|
| 355 | */
|
---|
| 356 | ondata: AsyncFlateStreamHandler;
|
---|
| 357 | /**
|
---|
| 358 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 359 | */
|
---|
| 360 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 361 | /**
|
---|
| 362 | * The number of compressed bytes buffered in the stream
|
---|
| 363 | */
|
---|
| 364 | queuedSize: number;
|
---|
| 365 | /**
|
---|
| 366 | * Creates an asynchronous DEFLATE decompression stream
|
---|
| 367 | * @param opts The decompression options
|
---|
| 368 | * @param cb The callback to call whenever data is inflated
|
---|
| 369 | */
|
---|
| 370 | constructor(opts: InflateStreamOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 371 | /**
|
---|
| 372 | * Creates an asynchronous DEFLATE decompression stream
|
---|
| 373 | * @param cb The callback to call whenever data is inflated
|
---|
| 374 | */
|
---|
| 375 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 376 | /**
|
---|
| 377 | * Pushes a chunk to be inflated
|
---|
| 378 | * @param chunk The chunk to push
|
---|
| 379 | * @param final Whether this is the last chunk
|
---|
| 380 | */
|
---|
| 381 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 382 | /**
|
---|
| 383 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 384 | * push() will silently fail.
|
---|
| 385 | */
|
---|
| 386 | terminate: AsyncTerminable;
|
---|
| 387 | }
|
---|
| 388 | /**
|
---|
| 389 | * Asynchronously expands DEFLATE data with no wrapper
|
---|
| 390 | * @param data The data to decompress
|
---|
| 391 | * @param opts The decompression options
|
---|
| 392 | * @param cb The function to be called upon decompression completion
|
---|
| 393 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 394 | */
|
---|
| 395 | export declare function inflate(data: Uint8Array, opts: AsyncInflateOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 396 | /**
|
---|
| 397 | * Asynchronously expands DEFLATE data with no wrapper
|
---|
| 398 | * @param data The data to decompress
|
---|
| 399 | * @param cb The function to be called upon decompression completion
|
---|
| 400 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 401 | */
|
---|
| 402 | export declare function inflate(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 403 | /**
|
---|
| 404 | * Expands DEFLATE data with no wrapper
|
---|
| 405 | * @param data The data to decompress
|
---|
| 406 | * @param opts The decompression options
|
---|
| 407 | * @returns The decompressed version of the data
|
---|
| 408 | */
|
---|
| 409 | export declare function inflateSync(data: Uint8Array, opts?: InflateOptions): Uint8Array;
|
---|
| 410 | /**
|
---|
| 411 | * Streaming GZIP compression
|
---|
| 412 | */
|
---|
| 413 | export declare class Gzip {
|
---|
| 414 | private c;
|
---|
| 415 | private l;
|
---|
| 416 | private v;
|
---|
| 417 | private o;
|
---|
| 418 | private s;
|
---|
| 419 | /**
|
---|
| 420 | * The handler to call whenever data is available
|
---|
| 421 | */
|
---|
| 422 | ondata: FlateStreamHandler;
|
---|
| 423 | /**
|
---|
| 424 | * Creates a GZIP stream
|
---|
| 425 | * @param opts The compression options
|
---|
| 426 | * @param cb The callback to call whenever data is deflated
|
---|
| 427 | */
|
---|
| 428 | constructor(opts: GzipOptions, cb?: FlateStreamHandler);
|
---|
| 429 | /**
|
---|
| 430 | * Creates a GZIP stream
|
---|
| 431 | * @param cb The callback to call whenever data is deflated
|
---|
| 432 | */
|
---|
| 433 | constructor(cb?: FlateStreamHandler);
|
---|
| 434 | /**
|
---|
| 435 | * Pushes a chunk to be GZIPped
|
---|
| 436 | * @param chunk The chunk to push
|
---|
| 437 | * @param final Whether this is the last chunk
|
---|
| 438 | */
|
---|
| 439 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 440 | private p;
|
---|
| 441 | /**
|
---|
| 442 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 443 | * GZIPped output for small inputs.
|
---|
| 444 | */
|
---|
| 445 | flush(): void;
|
---|
| 446 | }
|
---|
| 447 | /**
|
---|
| 448 | * Asynchronous streaming GZIP compression
|
---|
| 449 | */
|
---|
| 450 | export declare class AsyncGzip {
|
---|
| 451 | /**
|
---|
| 452 | * The handler to call whenever data is available
|
---|
| 453 | */
|
---|
| 454 | ondata: AsyncFlateStreamHandler;
|
---|
| 455 | /**
|
---|
| 456 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 457 | */
|
---|
| 458 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 459 | /**
|
---|
| 460 | * The number of uncompressed bytes buffered in the stream
|
---|
| 461 | */
|
---|
| 462 | queuedSize: number;
|
---|
| 463 | /**
|
---|
| 464 | * Creates an asynchronous GZIP stream
|
---|
| 465 | * @param opts The compression options
|
---|
| 466 | * @param cb The callback to call whenever data is deflated
|
---|
| 467 | */
|
---|
| 468 | constructor(opts: GzipOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 469 | /**
|
---|
| 470 | * Creates an asynchronous GZIP stream
|
---|
| 471 | * @param cb The callback to call whenever data is deflated
|
---|
| 472 | */
|
---|
| 473 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 474 | /**
|
---|
| 475 | * Pushes a chunk to be GZIPped
|
---|
| 476 | * @param chunk The chunk to push
|
---|
| 477 | * @param final Whether this is the last chunk
|
---|
| 478 | */
|
---|
| 479 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 480 | /**
|
---|
| 481 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 482 | * GZIPped output for small inputs.
|
---|
| 483 | */
|
---|
| 484 | flush(): void;
|
---|
| 485 | /**
|
---|
| 486 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 487 | * push() will silently fail.
|
---|
| 488 | */
|
---|
| 489 | terminate: AsyncTerminable;
|
---|
| 490 | }
|
---|
| 491 | /**
|
---|
| 492 | * Asynchronously compresses data with GZIP
|
---|
| 493 | * @param data The data to compress
|
---|
| 494 | * @param opts The compression options
|
---|
| 495 | * @param cb The function to be called upon compression completion
|
---|
| 496 | * @returns A function that can be used to immediately terminate the compression
|
---|
| 497 | */
|
---|
| 498 | export declare function gzip(data: Uint8Array, opts: AsyncGzipOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 499 | /**
|
---|
| 500 | * Asynchronously compresses data with GZIP
|
---|
| 501 | * @param data The data to compress
|
---|
| 502 | * @param cb The function to be called upon compression completion
|
---|
| 503 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 504 | */
|
---|
| 505 | export declare function gzip(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 506 | /**
|
---|
| 507 | * Compresses data with GZIP
|
---|
| 508 | * @param data The data to compress
|
---|
| 509 | * @param opts The compression options
|
---|
| 510 | * @returns The gzipped version of the data
|
---|
| 511 | */
|
---|
| 512 | export declare function gzipSync(data: Uint8Array, opts?: GzipOptions): Uint8Array;
|
---|
| 513 | /**
|
---|
| 514 | * Handler for new GZIP members in concatenated GZIP streams. Useful for building indices used to perform random-access reads on compressed files.
|
---|
| 515 | * @param offset The offset of the new member relative to the start of the stream
|
---|
| 516 | */
|
---|
| 517 | export type GunzipMemberHandler = (offset: number) => void;
|
---|
| 518 | /**
|
---|
| 519 | * Streaming single or multi-member GZIP decompression
|
---|
| 520 | */
|
---|
| 521 | export declare class Gunzip {
|
---|
| 522 | private v;
|
---|
| 523 | private r;
|
---|
| 524 | private o;
|
---|
| 525 | private p;
|
---|
| 526 | private s;
|
---|
| 527 | /**
|
---|
| 528 | * The handler to call whenever data is available
|
---|
| 529 | */
|
---|
| 530 | ondata: FlateStreamHandler;
|
---|
| 531 | /**
|
---|
| 532 | * The handler to call whenever a new GZIP member is found
|
---|
| 533 | */
|
---|
| 534 | onmember?: GunzipMemberHandler;
|
---|
| 535 | /**
|
---|
| 536 | * Creates a GUNZIP stream
|
---|
| 537 | * @param opts The decompression options
|
---|
| 538 | * @param cb The callback to call whenever data is inflated
|
---|
| 539 | */
|
---|
| 540 | constructor(opts: GunzipStreamOptions, cb?: FlateStreamHandler);
|
---|
| 541 | /**
|
---|
| 542 | * Creates a GUNZIP stream
|
---|
| 543 | * @param cb The callback to call whenever data is inflated
|
---|
| 544 | */
|
---|
| 545 | constructor(cb?: FlateStreamHandler);
|
---|
| 546 | /**
|
---|
| 547 | * Pushes a chunk to be GUNZIPped
|
---|
| 548 | * @param chunk The chunk to push
|
---|
| 549 | * @param final Whether this is the last chunk
|
---|
| 550 | */
|
---|
| 551 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 552 | }
|
---|
| 553 | /**
|
---|
| 554 | * Asynchronous streaming single or multi-member GZIP decompression
|
---|
| 555 | */
|
---|
| 556 | export declare class AsyncGunzip {
|
---|
| 557 | /**
|
---|
| 558 | * The handler to call whenever data is available
|
---|
| 559 | */
|
---|
| 560 | ondata: AsyncFlateStreamHandler;
|
---|
| 561 | /**
|
---|
| 562 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 563 | */
|
---|
| 564 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 565 | /**
|
---|
| 566 | * The number of compressed bytes buffered in the stream
|
---|
| 567 | */
|
---|
| 568 | queuedSize: number;
|
---|
| 569 | /**
|
---|
| 570 | * The handler to call whenever a new GZIP member is found
|
---|
| 571 | */
|
---|
| 572 | onmember?: GunzipMemberHandler;
|
---|
| 573 | /**
|
---|
| 574 | * Creates an asynchronous GUNZIP stream
|
---|
| 575 | * @param opts The decompression options
|
---|
| 576 | * @param cb The callback to call whenever data is inflated
|
---|
| 577 | */
|
---|
| 578 | constructor(opts: GunzipStreamOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 579 | /**
|
---|
| 580 | * Creates an asynchronous GUNZIP stream
|
---|
| 581 | * @param cb The callback to call whenever data is inflated
|
---|
| 582 | */
|
---|
| 583 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 584 | /**
|
---|
| 585 | * Pushes a chunk to be GUNZIPped
|
---|
| 586 | * @param chunk The chunk to push
|
---|
| 587 | * @param final Whether this is the last chunk
|
---|
| 588 | */
|
---|
| 589 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 590 | /**
|
---|
| 591 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 592 | * push() will silently fail.
|
---|
| 593 | */
|
---|
| 594 | terminate: AsyncTerminable;
|
---|
| 595 | }
|
---|
| 596 | /**
|
---|
| 597 | * Asynchronously expands GZIP data
|
---|
| 598 | * @param data The data to decompress
|
---|
| 599 | * @param opts The decompression options
|
---|
| 600 | * @param cb The function to be called upon decompression completion
|
---|
| 601 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 602 | */
|
---|
| 603 | export declare function gunzip(data: Uint8Array, opts: AsyncGunzipOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 604 | /**
|
---|
| 605 | * Asynchronously expands GZIP data
|
---|
| 606 | * @param data The data to decompress
|
---|
| 607 | * @param cb The function to be called upon decompression completion
|
---|
| 608 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 609 | */
|
---|
| 610 | export declare function gunzip(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 611 | /**
|
---|
| 612 | * Expands GZIP data
|
---|
| 613 | * @param data The data to decompress
|
---|
| 614 | * @param opts The decompression options
|
---|
| 615 | * @returns The decompressed version of the data
|
---|
| 616 | */
|
---|
| 617 | export declare function gunzipSync(data: Uint8Array, opts?: GunzipOptions): Uint8Array;
|
---|
| 618 | /**
|
---|
| 619 | * Streaming Zlib compression
|
---|
| 620 | */
|
---|
| 621 | export declare class Zlib {
|
---|
| 622 | private c;
|
---|
| 623 | private v;
|
---|
| 624 | private o;
|
---|
| 625 | private s;
|
---|
| 626 | /**
|
---|
| 627 | * The handler to call whenever data is available
|
---|
| 628 | */
|
---|
| 629 | ondata: FlateStreamHandler;
|
---|
| 630 | /**
|
---|
| 631 | * Creates a Zlib stream
|
---|
| 632 | * @param opts The compression options
|
---|
| 633 | * @param cb The callback to call whenever data is deflated
|
---|
| 634 | */
|
---|
| 635 | constructor(opts: ZlibOptions, cb?: FlateStreamHandler);
|
---|
| 636 | /**
|
---|
| 637 | * Creates a Zlib stream
|
---|
| 638 | * @param cb The callback to call whenever data is deflated
|
---|
| 639 | */
|
---|
| 640 | constructor(cb?: FlateStreamHandler);
|
---|
| 641 | /**
|
---|
| 642 | * Pushes a chunk to be zlibbed
|
---|
| 643 | * @param chunk The chunk to push
|
---|
| 644 | * @param final Whether this is the last chunk
|
---|
| 645 | */
|
---|
| 646 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 647 | private p;
|
---|
| 648 | /**
|
---|
| 649 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 650 | * zlibbed output for small inputs.
|
---|
| 651 | */
|
---|
| 652 | flush(): void;
|
---|
| 653 | }
|
---|
| 654 | /**
|
---|
| 655 | * Asynchronous streaming Zlib compression
|
---|
| 656 | */
|
---|
| 657 | export declare class AsyncZlib {
|
---|
| 658 | /**
|
---|
| 659 | * The handler to call whenever data is available
|
---|
| 660 | */
|
---|
| 661 | ondata: AsyncFlateStreamHandler;
|
---|
| 662 | /**
|
---|
| 663 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 664 | */
|
---|
| 665 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 666 | /**
|
---|
| 667 | * The number of uncompressed bytes buffered in the stream
|
---|
| 668 | */
|
---|
| 669 | queuedSize: number;
|
---|
| 670 | /**
|
---|
| 671 | * Creates an asynchronous Zlib stream
|
---|
| 672 | * @param opts The compression options
|
---|
| 673 | * @param cb The callback to call whenever data is deflated
|
---|
| 674 | */
|
---|
| 675 | constructor(opts: ZlibOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 676 | /**
|
---|
| 677 | * Creates an asynchronous Zlib stream
|
---|
| 678 | * @param cb The callback to call whenever data is deflated
|
---|
| 679 | */
|
---|
| 680 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 681 | /**
|
---|
| 682 | * Pushes a chunk to be deflated
|
---|
| 683 | * @param chunk The chunk to push
|
---|
| 684 | * @param final Whether this is the last chunk
|
---|
| 685 | */
|
---|
| 686 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 687 | /**
|
---|
| 688 | * Flushes buffered uncompressed data. Useful to immediately retrieve the
|
---|
| 689 | * zlibbed output for small inputs.
|
---|
| 690 | */
|
---|
| 691 | flush(): void;
|
---|
| 692 | /**
|
---|
| 693 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 694 | * push() will silently fail.
|
---|
| 695 | */
|
---|
| 696 | terminate: AsyncTerminable;
|
---|
| 697 | }
|
---|
| 698 | /**
|
---|
| 699 | * Asynchronously compresses data with Zlib
|
---|
| 700 | * @param data The data to compress
|
---|
| 701 | * @param opts The compression options
|
---|
| 702 | * @param cb The function to be called upon compression completion
|
---|
| 703 | */
|
---|
| 704 | export declare function zlib(data: Uint8Array, opts: AsyncZlibOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 705 | /**
|
---|
| 706 | * Asynchronously compresses data with Zlib
|
---|
| 707 | * @param data The data to compress
|
---|
| 708 | * @param cb The function to be called upon compression completion
|
---|
| 709 | * @returns A function that can be used to immediately terminate the compression
|
---|
| 710 | */
|
---|
| 711 | export declare function zlib(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 712 | /**
|
---|
| 713 | * Compress data with Zlib
|
---|
| 714 | * @param data The data to compress
|
---|
| 715 | * @param opts The compression options
|
---|
| 716 | * @returns The zlib-compressed version of the data
|
---|
| 717 | */
|
---|
| 718 | export declare function zlibSync(data: Uint8Array, opts?: ZlibOptions): Uint8Array;
|
---|
| 719 | /**
|
---|
| 720 | * Streaming Zlib decompression
|
---|
| 721 | */
|
---|
| 722 | export declare class Unzlib {
|
---|
| 723 | private v;
|
---|
| 724 | private p;
|
---|
| 725 | /**
|
---|
| 726 | * The handler to call whenever data is available
|
---|
| 727 | */
|
---|
| 728 | ondata: FlateStreamHandler;
|
---|
| 729 | /**
|
---|
| 730 | * Creates a Zlib decompression stream
|
---|
| 731 | * @param opts The decompression options
|
---|
| 732 | * @param cb The callback to call whenever data is inflated
|
---|
| 733 | */
|
---|
| 734 | constructor(opts: UnzlibStreamOptions, cb?: FlateStreamHandler);
|
---|
| 735 | /**
|
---|
| 736 | * Creates a Zlib decompression stream
|
---|
| 737 | * @param cb The callback to call whenever data is inflated
|
---|
| 738 | */
|
---|
| 739 | constructor(cb?: FlateStreamHandler);
|
---|
| 740 | /**
|
---|
| 741 | * Pushes a chunk to be unzlibbed
|
---|
| 742 | * @param chunk The chunk to push
|
---|
| 743 | * @param final Whether this is the last chunk
|
---|
| 744 | */
|
---|
| 745 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 746 | }
|
---|
| 747 | /**
|
---|
| 748 | * Asynchronous streaming Zlib decompression
|
---|
| 749 | */
|
---|
| 750 | export declare class AsyncUnzlib {
|
---|
| 751 | /**
|
---|
| 752 | * The handler to call whenever data is available
|
---|
| 753 | */
|
---|
| 754 | ondata: AsyncFlateStreamHandler;
|
---|
| 755 | /**
|
---|
| 756 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 757 | */
|
---|
| 758 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 759 | /**
|
---|
| 760 | * The number of compressed bytes buffered in the stream
|
---|
| 761 | */
|
---|
| 762 | queuedSize: number;
|
---|
| 763 | /**
|
---|
| 764 | * Creates an asynchronous Zlib decompression stream
|
---|
| 765 | * @param opts The decompression options
|
---|
| 766 | * @param cb The callback to call whenever data is inflated
|
---|
| 767 | */
|
---|
| 768 | constructor(opts: UnzlibStreamOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 769 | /**
|
---|
| 770 | * Creates an asynchronous Zlib decompression stream
|
---|
| 771 | * @param cb The callback to call whenever data is inflated
|
---|
| 772 | */
|
---|
| 773 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 774 | /**
|
---|
| 775 | * Pushes a chunk to be decompressed from Zlib
|
---|
| 776 | * @param chunk The chunk to push
|
---|
| 777 | * @param final Whether this is the last chunk
|
---|
| 778 | */
|
---|
| 779 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 780 | /**
|
---|
| 781 | * A method to terminate the stream's internal worker. Subsequent calls to
|
---|
| 782 | * push() will silently fail.
|
---|
| 783 | */
|
---|
| 784 | terminate: AsyncTerminable;
|
---|
| 785 | }
|
---|
| 786 | /**
|
---|
| 787 | * Asynchronously expands Zlib data
|
---|
| 788 | * @param data The data to decompress
|
---|
| 789 | * @param opts The decompression options
|
---|
| 790 | * @param cb The function to be called upon decompression completion
|
---|
| 791 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 792 | */
|
---|
| 793 | export declare function unzlib(data: Uint8Array, opts: AsyncUnzlibOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 794 | /**
|
---|
| 795 | * Asynchronously expands Zlib data
|
---|
| 796 | * @param data The data to decompress
|
---|
| 797 | * @param cb The function to be called upon decompression completion
|
---|
| 798 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 799 | */
|
---|
| 800 | export declare function unzlib(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 801 | /**
|
---|
| 802 | * Expands Zlib data
|
---|
| 803 | * @param data The data to decompress
|
---|
| 804 | * @param opts The decompression options
|
---|
| 805 | * @returns The decompressed version of the data
|
---|
| 806 | */
|
---|
| 807 | export declare function unzlibSync(data: Uint8Array, opts?: UnzlibOptions): Uint8Array;
|
---|
| 808 | export { gzip as compress, AsyncGzip as AsyncCompress };
|
---|
| 809 | export { gzipSync as compressSync, Gzip as Compress };
|
---|
| 810 | /**
|
---|
| 811 | * Streaming GZIP, Zlib, or raw DEFLATE decompression
|
---|
| 812 | */
|
---|
| 813 | export declare class Decompress {
|
---|
| 814 | private G;
|
---|
| 815 | private I;
|
---|
| 816 | private Z;
|
---|
| 817 | private o;
|
---|
| 818 | private s;
|
---|
| 819 | private p;
|
---|
| 820 | /**
|
---|
| 821 | * The handler to call whenever data is available
|
---|
| 822 | */
|
---|
| 823 | ondata: FlateStreamHandler;
|
---|
| 824 | /**
|
---|
| 825 | * Creates a decompression stream
|
---|
| 826 | * @param opts The decompression options
|
---|
| 827 | * @param cb The callback to call whenever data is decompressed
|
---|
| 828 | */
|
---|
| 829 | constructor(opts: InflateStreamOptions, cb?: FlateStreamHandler);
|
---|
| 830 | /**
|
---|
| 831 | * Creates a decompression stream
|
---|
| 832 | * @param cb The callback to call whenever data is decompressed
|
---|
| 833 | */
|
---|
| 834 | constructor(cb?: FlateStreamHandler);
|
---|
| 835 | private i;
|
---|
| 836 | /**
|
---|
| 837 | * Pushes a chunk to be decompressed
|
---|
| 838 | * @param chunk The chunk to push
|
---|
| 839 | * @param final Whether this is the last chunk
|
---|
| 840 | */
|
---|
| 841 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 842 | }
|
---|
| 843 | /**
|
---|
| 844 | * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
|
---|
| 845 | */
|
---|
| 846 | export declare class AsyncDecompress {
|
---|
| 847 | private G;
|
---|
| 848 | private I;
|
---|
| 849 | private Z;
|
---|
| 850 | /**
|
---|
| 851 | * The handler to call whenever data is available
|
---|
| 852 | */
|
---|
| 853 | ondata: AsyncFlateStreamHandler;
|
---|
| 854 | /**
|
---|
| 855 | * The handler to call whenever buffered source data is processed (i.e. `queuedSize` updates)
|
---|
| 856 | */
|
---|
| 857 | ondrain?: AsyncFlateDrainHandler;
|
---|
| 858 | /**
|
---|
| 859 | * The number of compressed bytes buffered in the stream
|
---|
| 860 | */
|
---|
| 861 | queuedSize: number;
|
---|
| 862 | /**
|
---|
| 863 | * Creates an asynchronous decompression stream
|
---|
| 864 | * @param opts The decompression options
|
---|
| 865 | * @param cb The callback to call whenever data is decompressed
|
---|
| 866 | */
|
---|
| 867 | constructor(opts: InflateStreamOptions, cb?: AsyncFlateStreamHandler);
|
---|
| 868 | /**
|
---|
| 869 | * Creates an asynchronous decompression stream
|
---|
| 870 | * @param cb The callback to call whenever data is decompressed
|
---|
| 871 | */
|
---|
| 872 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 873 | private i;
|
---|
| 874 | /**
|
---|
| 875 | * Pushes a chunk to be decompressed
|
---|
| 876 | * @param chunk The chunk to push
|
---|
| 877 | * @param final Whether this is the last chunk
|
---|
| 878 | */
|
---|
| 879 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 880 | }
|
---|
| 881 | /**
|
---|
| 882 | * Asynchrononously expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
|
---|
| 883 | * @param data The data to decompress
|
---|
| 884 | * @param opts The decompression options
|
---|
| 885 | * @param cb The function to be called upon decompression completion
|
---|
| 886 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 887 | */
|
---|
| 888 | export declare function decompress(data: Uint8Array, opts: AsyncInflateOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 889 | /**
|
---|
| 890 | * Asynchrononously expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
|
---|
| 891 | * @param data The data to decompress
|
---|
| 892 | * @param cb The function to be called upon decompression completion
|
---|
| 893 | * @returns A function that can be used to immediately terminate the decompression
|
---|
| 894 | */
|
---|
| 895 | export declare function decompress(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
|
---|
| 896 | /**
|
---|
| 897 | * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
|
---|
| 898 | * @param data The data to decompress
|
---|
| 899 | * @param opts The decompression options
|
---|
| 900 | * @returns The decompressed version of the data
|
---|
| 901 | */
|
---|
| 902 | export declare function decompressSync(data: Uint8Array, opts?: InflateOptions): Uint8Array;
|
---|
| 903 | /**
|
---|
| 904 | * Attributes for files added to a ZIP archive object
|
---|
| 905 | */
|
---|
| 906 | export interface ZipAttributes {
|
---|
| 907 | /**
|
---|
| 908 | * The operating system of origin for this file. The value is defined
|
---|
| 909 | * by PKZIP's APPNOTE.txt, section 4.4.2.2. For example, 0 (the default)
|
---|
| 910 | * is MS/DOS, 3 is Unix, 19 is macOS.
|
---|
| 911 | */
|
---|
| 912 | os?: number;
|
---|
| 913 | /**
|
---|
| 914 | * The file's attributes. These are traditionally somewhat complicated
|
---|
| 915 | * and platform-dependent, so using them is scarcely necessary. However,
|
---|
| 916 | * here is a representation of what this is, bit by bit:
|
---|
| 917 | *
|
---|
| 918 | * `TTTTugtrwxrwxrwx0000000000ADVSHR`
|
---|
| 919 | *
|
---|
| 920 | * TTTT = file type (rarely useful)
|
---|
| 921 | *
|
---|
| 922 | * u = setuid, g = setgid, t = sticky
|
---|
| 923 | *
|
---|
| 924 | * rwx = user permissions, rwx = group permissions, rwx = other permissions
|
---|
| 925 | *
|
---|
| 926 | * 0000000000 = unused
|
---|
| 927 | *
|
---|
| 928 | * A = archive, D = directory, V = volume label, S = system file, H = hidden, R = read-only
|
---|
| 929 | *
|
---|
| 930 | * If you want to set the Unix permissions, for instance, just bit shift by 16, e.g. 0o644 << 16.
|
---|
| 931 | * Note that attributes usually only work in conjunction with the `os` setting: you must use
|
---|
| 932 | * `os` = 3 (Unix) if you want to set Unix permissions
|
---|
| 933 | */
|
---|
| 934 | attrs?: number;
|
---|
| 935 | /**
|
---|
| 936 | * Extra metadata to add to the file. This field is defined by PKZIP's APPNOTE.txt,
|
---|
| 937 | * section 4.4.28. At most 65,535 bytes may be used in each ID. The ID must be an
|
---|
| 938 | * integer between 0 and 65,535, inclusive.
|
---|
| 939 | *
|
---|
| 940 | * This field is incredibly rare and almost never needed except for compliance with
|
---|
| 941 | * proprietary standards and software.
|
---|
| 942 | */
|
---|
| 943 | extra?: Record<number, Uint8Array>;
|
---|
| 944 | /**
|
---|
| 945 | * The comment to attach to the file. This field is defined by PKZIP's APPNOTE.txt,
|
---|
| 946 | * section 4.4.26. The comment must be at most 65,535 bytes long UTF-8 encoded. This
|
---|
| 947 | * field is not read by consumer software.
|
---|
| 948 | */
|
---|
| 949 | comment?: string;
|
---|
| 950 | /**
|
---|
| 951 | * When the file was last modified. Defaults to the current time.
|
---|
| 952 | */
|
---|
| 953 | mtime?: GzipOptions['mtime'];
|
---|
| 954 | }
|
---|
| 955 | /**
|
---|
| 956 | * Options for creating a ZIP archive
|
---|
| 957 | */
|
---|
| 958 | export interface ZipOptions extends DeflateOptions, ZipAttributes {
|
---|
| 959 | }
|
---|
| 960 | /**
|
---|
| 961 | * Options for expanding a ZIP archive
|
---|
| 962 | */
|
---|
| 963 | export interface UnzipOptions {
|
---|
| 964 | /**
|
---|
| 965 | * A filter function to extract only certain files from a ZIP archive
|
---|
| 966 | */
|
---|
| 967 | filter?: UnzipFileFilter;
|
---|
| 968 | }
|
---|
| 969 | /**
|
---|
| 970 | * Options for asynchronously creating a ZIP archive
|
---|
| 971 | */
|
---|
| 972 | export interface AsyncZipOptions extends AsyncDeflateOptions, ZipAttributes {
|
---|
| 973 | }
|
---|
| 974 | /**
|
---|
| 975 | * Options for asynchronously expanding a ZIP archive
|
---|
| 976 | */
|
---|
| 977 | export interface AsyncUnzipOptions extends UnzipOptions {
|
---|
| 978 | }
|
---|
| 979 | /**
|
---|
| 980 | * A file that can be used to create a ZIP archive
|
---|
| 981 | */
|
---|
| 982 | export type ZippableFile = Uint8Array | Zippable | [Uint8Array | Zippable, ZipOptions];
|
---|
| 983 | /**
|
---|
| 984 | * A file that can be used to asynchronously create a ZIP archive
|
---|
| 985 | */
|
---|
| 986 | export type AsyncZippableFile = Uint8Array | AsyncZippable | [Uint8Array | AsyncZippable, AsyncZipOptions];
|
---|
| 987 | /**
|
---|
| 988 | * The complete directory structure of a ZIPpable archive
|
---|
| 989 | */
|
---|
| 990 | export interface Zippable {
|
---|
| 991 | [path: string]: ZippableFile;
|
---|
| 992 | }
|
---|
| 993 | /**
|
---|
| 994 | * The complete directory structure of an asynchronously ZIPpable archive
|
---|
| 995 | */
|
---|
| 996 | export interface AsyncZippable {
|
---|
| 997 | [path: string]: AsyncZippableFile;
|
---|
| 998 | }
|
---|
| 999 | /**
|
---|
| 1000 | * An unzipped archive. The full path of each file is used as the key,
|
---|
| 1001 | * and the file is the value
|
---|
| 1002 | */
|
---|
| 1003 | export interface Unzipped {
|
---|
| 1004 | [path: string]: Uint8Array;
|
---|
| 1005 | }
|
---|
| 1006 | /**
|
---|
| 1007 | * Handler for string generation streams
|
---|
| 1008 | * @param data The string output from the stream processor
|
---|
| 1009 | * @param final Whether this is the final block
|
---|
| 1010 | */
|
---|
| 1011 | export type StringStreamHandler = (data: string, final: boolean) => void;
|
---|
| 1012 | /**
|
---|
| 1013 | * Callback for asynchronous ZIP decompression
|
---|
| 1014 | * @param err Any error that occurred
|
---|
| 1015 | * @param data The decompressed ZIP archive
|
---|
| 1016 | */
|
---|
| 1017 | export type UnzipCallback = (err: FlateError | null, data: Unzipped) => void;
|
---|
| 1018 | /**
|
---|
| 1019 | * Handler for streaming ZIP decompression
|
---|
| 1020 | * @param file The file that was found in the archive
|
---|
| 1021 | */
|
---|
| 1022 | export type UnzipFileHandler = (file: UnzipFile) => void;
|
---|
| 1023 | /**
|
---|
| 1024 | * Streaming UTF-8 decoding
|
---|
| 1025 | */
|
---|
| 1026 | export declare class DecodeUTF8 {
|
---|
| 1027 | private p;
|
---|
| 1028 | private t;
|
---|
| 1029 | /**
|
---|
| 1030 | * Creates a UTF-8 decoding stream
|
---|
| 1031 | * @param cb The callback to call whenever data is decoded
|
---|
| 1032 | */
|
---|
| 1033 | constructor(cb?: StringStreamHandler);
|
---|
| 1034 | /**
|
---|
| 1035 | * Pushes a chunk to be decoded from UTF-8 binary
|
---|
| 1036 | * @param chunk The chunk to push
|
---|
| 1037 | * @param final Whether this is the last chunk
|
---|
| 1038 | */
|
---|
| 1039 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 1040 | /**
|
---|
| 1041 | * The handler to call whenever data is available
|
---|
| 1042 | */
|
---|
| 1043 | ondata: StringStreamHandler;
|
---|
| 1044 | }
|
---|
| 1045 | /**
|
---|
| 1046 | * Streaming UTF-8 encoding
|
---|
| 1047 | */
|
---|
| 1048 | export declare class EncodeUTF8 {
|
---|
| 1049 | private d;
|
---|
| 1050 | /**
|
---|
| 1051 | * Creates a UTF-8 decoding stream
|
---|
| 1052 | * @param cb The callback to call whenever data is encoded
|
---|
| 1053 | */
|
---|
| 1054 | constructor(cb?: FlateStreamHandler);
|
---|
| 1055 | /**
|
---|
| 1056 | * Pushes a chunk to be encoded to UTF-8
|
---|
| 1057 | * @param chunk The string data to push
|
---|
| 1058 | * @param final Whether this is the last chunk
|
---|
| 1059 | */
|
---|
| 1060 | push(chunk: string, final?: boolean): void;
|
---|
| 1061 | /**
|
---|
| 1062 | * The handler to call whenever data is available
|
---|
| 1063 | */
|
---|
| 1064 | ondata: FlateStreamHandler;
|
---|
| 1065 | }
|
---|
| 1066 | /**
|
---|
| 1067 | * Converts a string into a Uint8Array for use with compression/decompression methods
|
---|
| 1068 | * @param str The string to encode
|
---|
| 1069 | * @param latin1 Whether or not to interpret the data as Latin-1. This should
|
---|
| 1070 | * not need to be true unless decoding a binary string.
|
---|
| 1071 | * @returns The string encoded in UTF-8/Latin-1 binary
|
---|
| 1072 | */
|
---|
| 1073 | export declare function strToU8(str: string, latin1?: boolean): Uint8Array;
|
---|
| 1074 | /**
|
---|
| 1075 | * Converts a Uint8Array to a string
|
---|
| 1076 | * @param dat The data to decode to string
|
---|
| 1077 | * @param latin1 Whether or not to interpret the data as Latin-1. This should
|
---|
| 1078 | * not need to be true unless encoding to binary string.
|
---|
| 1079 | * @returns The original UTF-8/Latin-1 string
|
---|
| 1080 | */
|
---|
| 1081 | export declare function strFromU8(dat: Uint8Array, latin1?: boolean): string;
|
---|
| 1082 | /**
|
---|
| 1083 | * A stream that can be used to create a file in a ZIP archive
|
---|
| 1084 | */
|
---|
| 1085 | export interface ZipInputFile extends ZipAttributes {
|
---|
| 1086 | /**
|
---|
| 1087 | * The filename to associate with the data provided to this stream. If you
|
---|
| 1088 | * want a file in a subdirectory, use forward slashes as a separator (e.g.
|
---|
| 1089 | * `directory/filename.ext`). This will still work on Windows.
|
---|
| 1090 | */
|
---|
| 1091 | filename: string;
|
---|
| 1092 | /**
|
---|
| 1093 | * The size of the file in bytes. This attribute may be invalid after
|
---|
| 1094 | * the file is added to the ZIP archive; it must be correct only before the
|
---|
| 1095 | * stream completes.
|
---|
| 1096 | *
|
---|
| 1097 | * If you don't want to have to compute this yourself, consider extending the
|
---|
| 1098 | * ZipPassThrough class and overriding its process() method, or using one of
|
---|
| 1099 | * ZipDeflate or AsyncZipDeflate.
|
---|
| 1100 | */
|
---|
| 1101 | size: number;
|
---|
| 1102 | /**
|
---|
| 1103 | * A CRC of the original file contents. This attribute may be invalid after
|
---|
| 1104 | * the file is added to the ZIP archive; it must be correct only before the
|
---|
| 1105 | * stream completes.
|
---|
| 1106 | *
|
---|
| 1107 | * If you don't want to have to generate this yourself, consider extending the
|
---|
| 1108 | * ZipPassThrough class and overriding its process() method, or using one of
|
---|
| 1109 | * ZipDeflate or AsyncZipDeflate.
|
---|
| 1110 | */
|
---|
| 1111 | crc: number;
|
---|
| 1112 | /**
|
---|
| 1113 | * The compression format for the data stream. This number is determined by
|
---|
| 1114 | * the spec in PKZIP's APPNOTE.txt, section 4.4.5. For example, 0 = no
|
---|
| 1115 | * compression, 8 = deflate, 14 = LZMA
|
---|
| 1116 | */
|
---|
| 1117 | compression: number;
|
---|
| 1118 | /**
|
---|
| 1119 | * Bits 1 and 2 of the general purpose bit flag, specified in PKZIP's
|
---|
| 1120 | * APPNOTE.txt, section 4.4.4. Should be between 0 and 3. This is unlikely
|
---|
| 1121 | * to be necessary.
|
---|
| 1122 | */
|
---|
| 1123 | flag?: number;
|
---|
| 1124 | /**
|
---|
| 1125 | * The handler to be called when data is added. After passing this stream to
|
---|
| 1126 | * the ZIP file object, this handler will always be defined. To call it:
|
---|
| 1127 | *
|
---|
| 1128 | * `stream.ondata(error, chunk, final)`
|
---|
| 1129 | *
|
---|
| 1130 | * error = any error that occurred (null if there was no error)
|
---|
| 1131 | *
|
---|
| 1132 | * chunk = a Uint8Array of the data that was added (null if there was an
|
---|
| 1133 | * error)
|
---|
| 1134 | *
|
---|
| 1135 | * final = boolean, whether this is the final chunk in the stream
|
---|
| 1136 | */
|
---|
| 1137 | ondata?: AsyncFlateStreamHandler;
|
---|
| 1138 | /**
|
---|
| 1139 | * A method called when the stream is no longer needed, for clean-up
|
---|
| 1140 | * purposes. This will not always be called after the stream completes,
|
---|
| 1141 | * so you may wish to call this.terminate() after the final chunk is
|
---|
| 1142 | * processed if you have clean-up logic.
|
---|
| 1143 | */
|
---|
| 1144 | terminate?: AsyncTerminable;
|
---|
| 1145 | }
|
---|
| 1146 | /**
|
---|
| 1147 | * A pass-through stream to keep data uncompressed in a ZIP archive.
|
---|
| 1148 | */
|
---|
| 1149 | export declare class ZipPassThrough implements ZipInputFile {
|
---|
| 1150 | filename: string;
|
---|
| 1151 | crc: number;
|
---|
| 1152 | size: number;
|
---|
| 1153 | compression: number;
|
---|
| 1154 | os?: number;
|
---|
| 1155 | attrs?: number;
|
---|
| 1156 | comment?: string;
|
---|
| 1157 | extra?: Record<number, Uint8Array>;
|
---|
| 1158 | mtime?: GzipOptions['mtime'];
|
---|
| 1159 | ondata: AsyncFlateStreamHandler;
|
---|
| 1160 | private c;
|
---|
| 1161 | /**
|
---|
| 1162 | * Creates a pass-through stream that can be added to ZIP archives
|
---|
| 1163 | * @param filename The filename to associate with this data stream
|
---|
| 1164 | */
|
---|
| 1165 | constructor(filename: string);
|
---|
| 1166 | /**
|
---|
| 1167 | * Processes a chunk and pushes to the output stream. You can override this
|
---|
| 1168 | * method in a subclass for custom behavior, but by default this passes
|
---|
| 1169 | * the data through. You must call this.ondata(err, chunk, final) at some
|
---|
| 1170 | * point in this method.
|
---|
| 1171 | * @param chunk The chunk to process
|
---|
| 1172 | * @param final Whether this is the last chunk
|
---|
| 1173 | */
|
---|
| 1174 | protected process(chunk: Uint8Array, final: boolean): void;
|
---|
| 1175 | /**
|
---|
| 1176 | * Pushes a chunk to be added. If you are subclassing this with a custom
|
---|
| 1177 | * compression algorithm, note that you must push data from the source
|
---|
| 1178 | * file only, pre-compression.
|
---|
| 1179 | * @param chunk The chunk to push
|
---|
| 1180 | * @param final Whether this is the last chunk
|
---|
| 1181 | */
|
---|
| 1182 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 1183 | }
|
---|
| 1184 | /**
|
---|
| 1185 | * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate
|
---|
| 1186 | * for better performance
|
---|
| 1187 | */
|
---|
| 1188 | export declare class ZipDeflate implements ZipInputFile {
|
---|
| 1189 | filename: string;
|
---|
| 1190 | crc: number;
|
---|
| 1191 | size: number;
|
---|
| 1192 | compression: number;
|
---|
| 1193 | flag: 0 | 1 | 2 | 3;
|
---|
| 1194 | os?: number;
|
---|
| 1195 | attrs?: number;
|
---|
| 1196 | comment?: string;
|
---|
| 1197 | extra?: Record<number, Uint8Array>;
|
---|
| 1198 | mtime?: GzipOptions['mtime'];
|
---|
| 1199 | ondata: AsyncFlateStreamHandler;
|
---|
| 1200 | private d;
|
---|
| 1201 | /**
|
---|
| 1202 | * Creates a DEFLATE stream that can be added to ZIP archives
|
---|
| 1203 | * @param filename The filename to associate with this data stream
|
---|
| 1204 | * @param opts The compression options
|
---|
| 1205 | */
|
---|
| 1206 | constructor(filename: string, opts?: DeflateOptions);
|
---|
| 1207 | process(chunk: Uint8Array, final: boolean): void;
|
---|
| 1208 | /**
|
---|
| 1209 | * Pushes a chunk to be deflated
|
---|
| 1210 | * @param chunk The chunk to push
|
---|
| 1211 | * @param final Whether this is the last chunk
|
---|
| 1212 | */
|
---|
| 1213 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 1214 | }
|
---|
| 1215 | /**
|
---|
| 1216 | * Asynchronous streaming DEFLATE compression for ZIP archives
|
---|
| 1217 | */
|
---|
| 1218 | export declare class AsyncZipDeflate implements ZipInputFile {
|
---|
| 1219 | filename: string;
|
---|
| 1220 | crc: number;
|
---|
| 1221 | size: number;
|
---|
| 1222 | compression: number;
|
---|
| 1223 | flag: 0 | 1 | 2 | 3;
|
---|
| 1224 | os?: number;
|
---|
| 1225 | attrs?: number;
|
---|
| 1226 | comment?: string;
|
---|
| 1227 | extra?: Record<number, Uint8Array>;
|
---|
| 1228 | mtime?: GzipOptions['mtime'];
|
---|
| 1229 | ondata: AsyncFlateStreamHandler;
|
---|
| 1230 | private d;
|
---|
| 1231 | terminate: AsyncTerminable;
|
---|
| 1232 | /**
|
---|
| 1233 | * Creates an asynchronous DEFLATE stream that can be added to ZIP archives
|
---|
| 1234 | * @param filename The filename to associate with this data stream
|
---|
| 1235 | * @param opts The compression options
|
---|
| 1236 | */
|
---|
| 1237 | constructor(filename: string, opts?: DeflateOptions);
|
---|
| 1238 | process(chunk: Uint8Array, final: boolean): void;
|
---|
| 1239 | /**
|
---|
| 1240 | * Pushes a chunk to be deflated
|
---|
| 1241 | * @param chunk The chunk to push
|
---|
| 1242 | * @param final Whether this is the last chunk
|
---|
| 1243 | */
|
---|
| 1244 | push(chunk: Uint8Array, final?: boolean): void;
|
---|
| 1245 | }
|
---|
| 1246 | /**
|
---|
| 1247 | * A zippable archive to which files can incrementally be added
|
---|
| 1248 | */
|
---|
| 1249 | export declare class Zip {
|
---|
| 1250 | private u;
|
---|
| 1251 | private d;
|
---|
| 1252 | /**
|
---|
| 1253 | * Creates an empty ZIP archive to which files can be added
|
---|
| 1254 | * @param cb The callback to call whenever data for the generated ZIP archive
|
---|
| 1255 | * is available
|
---|
| 1256 | */
|
---|
| 1257 | constructor(cb?: AsyncFlateStreamHandler);
|
---|
| 1258 | /**
|
---|
| 1259 | * Adds a file to the ZIP archive
|
---|
| 1260 | * @param file The file stream to add
|
---|
| 1261 | */
|
---|
| 1262 | add(file: ZipInputFile): void;
|
---|
| 1263 | /**
|
---|
| 1264 | * Ends the process of adding files and prepares to emit the final chunks.
|
---|
| 1265 | * This *must* be called after adding all desired files for the resulting
|
---|
| 1266 | * ZIP file to work properly.
|
---|
| 1267 | */
|
---|
| 1268 | end(): void;
|
---|
| 1269 | private e;
|
---|
| 1270 | /**
|
---|
| 1271 | * A method to terminate any internal workers used by the stream. Subsequent
|
---|
| 1272 | * calls to add() will fail.
|
---|
| 1273 | */
|
---|
| 1274 | terminate(): void;
|
---|
| 1275 | /**
|
---|
| 1276 | * The handler to call whenever data is available
|
---|
| 1277 | */
|
---|
| 1278 | ondata: AsyncFlateStreamHandler;
|
---|
| 1279 | }
|
---|
| 1280 | /**
|
---|
| 1281 | * Asynchronously creates a ZIP file
|
---|
| 1282 | * @param data The directory structure for the ZIP archive
|
---|
| 1283 | * @param opts The main options, merged with per-file options
|
---|
| 1284 | * @param cb The callback to call with the generated ZIP archive
|
---|
| 1285 | * @returns A function that can be used to immediately terminate the compression
|
---|
| 1286 | */
|
---|
| 1287 | export declare function zip(data: AsyncZippable, opts: AsyncZipOptions, cb: FlateCallback): AsyncTerminable;
|
---|
| 1288 | /**
|
---|
| 1289 | * Asynchronously creates a ZIP file
|
---|
| 1290 | * @param data The directory structure for the ZIP archive
|
---|
| 1291 | * @param cb The callback to call with the generated ZIP archive
|
---|
| 1292 | * @returns A function that can be used to immediately terminate the compression
|
---|
| 1293 | */
|
---|
| 1294 | export declare function zip(data: AsyncZippable, cb: FlateCallback): AsyncTerminable;
|
---|
| 1295 | /**
|
---|
| 1296 | * Synchronously creates a ZIP file. Prefer using `zip` for better performance
|
---|
| 1297 | * with more than one file.
|
---|
| 1298 | * @param data The directory structure for the ZIP archive
|
---|
| 1299 | * @param opts The main options, merged with per-file options
|
---|
| 1300 | * @returns The generated ZIP archive
|
---|
| 1301 | */
|
---|
| 1302 | export declare function zipSync(data: Zippable, opts?: ZipOptions): Uint8Array;
|
---|
| 1303 | /**
|
---|
| 1304 | * A decoder for files in ZIP streams
|
---|
| 1305 | */
|
---|
| 1306 | export interface UnzipDecoder {
|
---|
| 1307 | /**
|
---|
| 1308 | * The handler to call whenever data is available
|
---|
| 1309 | */
|
---|
| 1310 | ondata: AsyncFlateStreamHandler;
|
---|
| 1311 | /**
|
---|
| 1312 | * Pushes a chunk to be decompressed
|
---|
| 1313 | * @param data The data in this chunk. Do not consume (detach) this data.
|
---|
| 1314 | * @param final Whether this is the last chunk in the data stream
|
---|
| 1315 | */
|
---|
| 1316 | push(data: Uint8Array, final: boolean): void;
|
---|
| 1317 | /**
|
---|
| 1318 | * A method to terminate any internal workers used by the stream. Subsequent
|
---|
| 1319 | * calls to push() should silently fail.
|
---|
| 1320 | */
|
---|
| 1321 | terminate?: AsyncTerminable;
|
---|
| 1322 | }
|
---|
| 1323 | /**
|
---|
| 1324 | * A constructor for a decoder for unzip streams
|
---|
| 1325 | */
|
---|
| 1326 | export interface UnzipDecoderConstructor {
|
---|
| 1327 | /**
|
---|
| 1328 | * Creates an instance of the decoder
|
---|
| 1329 | * @param filename The name of the file
|
---|
| 1330 | * @param size The compressed size of the file
|
---|
| 1331 | * @param originalSize The original size of the file
|
---|
| 1332 | */
|
---|
| 1333 | new (filename: string, size?: number, originalSize?: number): UnzipDecoder;
|
---|
| 1334 | /**
|
---|
| 1335 | * The compression format for the data stream. This number is determined by
|
---|
| 1336 | * the spec in PKZIP's APPNOTE.txt, section 4.4.5. For example, 0 = no
|
---|
| 1337 | * compression, 8 = deflate, 14 = LZMA
|
---|
| 1338 | */
|
---|
| 1339 | compression: number;
|
---|
| 1340 | }
|
---|
| 1341 | /**
|
---|
| 1342 | * Information about a file to be extracted from a ZIP archive
|
---|
| 1343 | */
|
---|
| 1344 | export interface UnzipFileInfo {
|
---|
| 1345 | /**
|
---|
| 1346 | * The name of the file
|
---|
| 1347 | */
|
---|
| 1348 | name: string;
|
---|
| 1349 | /**
|
---|
| 1350 | * The compressed size of the file
|
---|
| 1351 | */
|
---|
| 1352 | size: number;
|
---|
| 1353 | /**
|
---|
| 1354 | * The original size of the file
|
---|
| 1355 | */
|
---|
| 1356 | originalSize: number;
|
---|
| 1357 | /**
|
---|
| 1358 | * The compression format for the data stream. This number is determined by
|
---|
| 1359 | * the spec in PKZIP's APPNOTE.txt, section 4.4.5. For example, 0 = no
|
---|
| 1360 | * compression, 8 = deflate, 14 = LZMA. If the filter function returns true
|
---|
| 1361 | * but this value is not 8, the unzip function will throw.
|
---|
| 1362 | */
|
---|
| 1363 | compression: number;
|
---|
| 1364 | }
|
---|
| 1365 | /**
|
---|
| 1366 | * A filter for files to be extracted during the unzipping process
|
---|
| 1367 | * @param file The info for the current file being processed
|
---|
| 1368 | * @returns Whether or not to extract the current file
|
---|
| 1369 | */
|
---|
| 1370 | export type UnzipFileFilter = (file: UnzipFileInfo) => boolean;
|
---|
| 1371 | /**
|
---|
| 1372 | * Streaming file extraction from ZIP archives
|
---|
| 1373 | */
|
---|
| 1374 | export interface UnzipFile {
|
---|
| 1375 | /**
|
---|
| 1376 | * The handler to call whenever data is available
|
---|
| 1377 | */
|
---|
| 1378 | ondata: AsyncFlateStreamHandler;
|
---|
| 1379 | /**
|
---|
| 1380 | * The name of the file
|
---|
| 1381 | */
|
---|
| 1382 | name: string;
|
---|
| 1383 | /**
|
---|
| 1384 | * The compression format for the data stream. This number is determined by
|
---|
| 1385 | * the spec in PKZIP's APPNOTE.txt, section 4.4.5. For example, 0 = no
|
---|
| 1386 | * compression, 8 = deflate, 14 = LZMA. If start() is called but there is no
|
---|
| 1387 | * decompression stream available for this method, start() will throw.
|
---|
| 1388 | */
|
---|
| 1389 | compression: number;
|
---|
| 1390 | /**
|
---|
| 1391 | * The compressed size of the file. Will not be present for archives created
|
---|
| 1392 | * in a streaming fashion.
|
---|
| 1393 | */
|
---|
| 1394 | size?: number;
|
---|
| 1395 | /**
|
---|
| 1396 | * The original size of the file. Will not be present for archives created
|
---|
| 1397 | * in a streaming fashion.
|
---|
| 1398 | */
|
---|
| 1399 | originalSize?: number;
|
---|
| 1400 | /**
|
---|
| 1401 | * Starts reading from the stream. Calling this function will always enable
|
---|
| 1402 | * this stream, but ocassionally the stream will be enabled even without
|
---|
| 1403 | * this being called.
|
---|
| 1404 | */
|
---|
| 1405 | start(): void;
|
---|
| 1406 | /**
|
---|
| 1407 | * A method to terminate any internal workers used by the stream. ondata
|
---|
| 1408 | * will not be called any further.
|
---|
| 1409 | */
|
---|
| 1410 | terminate: AsyncTerminable;
|
---|
| 1411 | }
|
---|
| 1412 | /**
|
---|
| 1413 | * Streaming pass-through decompression for ZIP archives
|
---|
| 1414 | */
|
---|
| 1415 | export declare class UnzipPassThrough implements UnzipDecoder {
|
---|
| 1416 | static compression: number;
|
---|
| 1417 | ondata: AsyncFlateStreamHandler;
|
---|
| 1418 | push(data: Uint8Array, final: boolean): void;
|
---|
| 1419 | }
|
---|
| 1420 | /**
|
---|
| 1421 | * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for
|
---|
| 1422 | * better performance.
|
---|
| 1423 | */
|
---|
| 1424 | export declare class UnzipInflate implements UnzipDecoder {
|
---|
| 1425 | static compression: number;
|
---|
| 1426 | private i;
|
---|
| 1427 | ondata: AsyncFlateStreamHandler;
|
---|
| 1428 | /**
|
---|
| 1429 | * Creates a DEFLATE decompression that can be used in ZIP archives
|
---|
| 1430 | */
|
---|
| 1431 | constructor();
|
---|
| 1432 | push(data: Uint8Array, final: boolean): void;
|
---|
| 1433 | }
|
---|
| 1434 | /**
|
---|
| 1435 | * Asynchronous streaming DEFLATE decompression for ZIP archives
|
---|
| 1436 | */
|
---|
| 1437 | export declare class AsyncUnzipInflate implements UnzipDecoder {
|
---|
| 1438 | static compression: number;
|
---|
| 1439 | private i;
|
---|
| 1440 | ondata: AsyncFlateStreamHandler;
|
---|
| 1441 | terminate: AsyncTerminable;
|
---|
| 1442 | /**
|
---|
| 1443 | * Creates a DEFLATE decompression that can be used in ZIP archives
|
---|
| 1444 | */
|
---|
| 1445 | constructor(_: string, sz?: number);
|
---|
| 1446 | push(data: Uint8Array, final: boolean): void;
|
---|
| 1447 | }
|
---|
| 1448 | /**
|
---|
| 1449 | * A ZIP archive decompression stream that emits files as they are discovered
|
---|
| 1450 | */
|
---|
| 1451 | export declare class Unzip {
|
---|
| 1452 | private d;
|
---|
| 1453 | private c;
|
---|
| 1454 | private p;
|
---|
| 1455 | private k;
|
---|
| 1456 | private o;
|
---|
| 1457 | /**
|
---|
| 1458 | * Creates a ZIP decompression stream
|
---|
| 1459 | * @param cb The callback to call whenever a file in the ZIP archive is found
|
---|
| 1460 | */
|
---|
| 1461 | constructor(cb?: UnzipFileHandler);
|
---|
| 1462 | /**
|
---|
| 1463 | * Pushes a chunk to be unzipped
|
---|
| 1464 | * @param chunk The chunk to push
|
---|
| 1465 | * @param final Whether this is the last chunk
|
---|
| 1466 | */
|
---|
| 1467 | push(chunk: Uint8Array, final?: boolean): any;
|
---|
| 1468 | /**
|
---|
| 1469 | * Registers a decoder with the stream, allowing for files compressed with
|
---|
| 1470 | * the compression type provided to be expanded correctly
|
---|
| 1471 | * @param decoder The decoder constructor
|
---|
| 1472 | */
|
---|
| 1473 | register(decoder: UnzipDecoderConstructor): void;
|
---|
| 1474 | /**
|
---|
| 1475 | * The handler to call whenever a file is discovered
|
---|
| 1476 | */
|
---|
| 1477 | onfile: UnzipFileHandler;
|
---|
| 1478 | }
|
---|
| 1479 | /**
|
---|
| 1480 | * Asynchronously decompresses a ZIP archive
|
---|
| 1481 | * @param data The raw compressed ZIP file
|
---|
| 1482 | * @param opts The ZIP extraction options
|
---|
| 1483 | * @param cb The callback to call with the decompressed files
|
---|
| 1484 | * @returns A function that can be used to immediately terminate the unzipping
|
---|
| 1485 | */
|
---|
| 1486 | export declare function unzip(data: Uint8Array, opts: AsyncUnzipOptions, cb: UnzipCallback): AsyncTerminable;
|
---|
| 1487 | /**
|
---|
| 1488 | * Asynchronously decompresses a ZIP archive
|
---|
| 1489 | * @param data The raw compressed ZIP file
|
---|
| 1490 | * @param cb The callback to call with the decompressed files
|
---|
| 1491 | * @returns A function that can be used to immediately terminate the unzipping
|
---|
| 1492 | */
|
---|
| 1493 | export declare function unzip(data: Uint8Array, cb: UnzipCallback): AsyncTerminable;
|
---|
| 1494 | /**
|
---|
| 1495 | * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
|
---|
| 1496 | * performance with more than one file.
|
---|
| 1497 | * @param data The raw compressed ZIP file
|
---|
| 1498 | * @param opts The ZIP extraction options
|
---|
| 1499 | * @returns The decompressed files
|
---|
| 1500 | */
|
---|
| 1501 | export declare function unzipSync(data: Uint8Array, opts?: UnzipOptions): Unzipped;
|
---|