index.d.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /**
  2. * Options for compressing data into a DEFLATE format
  3. */
  4. export interface DeflateOptions {
  5. /**
  6. * The level of compression to use, ranging from 0-9.
  7. *
  8. * 0 will store the data without compression.
  9. * 1 is fastest but compresses the worst, 9 is slowest but compresses the best.
  10. * The default level is 6.
  11. *
  12. * Typically, binary data benefits much more from higher values than text data.
  13. * In both cases, higher values usually take disproportionately longer than the reduction in final size that results.
  14. *
  15. * For example, a 1 MB text file could:
  16. * - become 1.01 MB with level 0 in 1ms
  17. * - become 400 kB with level 1 in 10ms
  18. * - become 320 kB with level 9 in 100ms
  19. */
  20. level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
  21. /**
  22. * The memory level to use, ranging from 0-12. Increasing this increases speed and compression ratio at the cost of memory.
  23. *
  24. * 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.
  25. * It is recommended not to lower the value below 4, since that tends to hurt performance.
  26. * In addition, values above 8 tend to help very little on most data and can even hurt performance.
  27. *
  28. * The default value is automatically determined based on the size of the input data.
  29. */
  30. mem?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
  31. }
  32. /**
  33. * Options for compressing data into a GZIP format
  34. */
  35. export interface GzipOptions extends DeflateOptions {
  36. /**
  37. * When the file was last modified. Defaults to the current time.
  38. * If you're using GZIP, set this to 0 to avoid revealing a modification date entirely.
  39. */
  40. mtime?: Date | string | number;
  41. /**
  42. * The filename of the data. If the `gunzip` command is used to decompress the data, it will output a file
  43. * with this name instead of the name of the compressed file.
  44. */
  45. filename?: string;
  46. }
  47. /**
  48. * Options for compressing data into a Zlib format
  49. */
  50. export interface ZlibOptions extends DeflateOptions {
  51. }
  52. /**
  53. * Handler for data (de)compression streams
  54. * @param data The data output from the stream processor
  55. * @param final Whether this is the final block
  56. */
  57. export declare type FlateStreamHandler = (data: Uint8Array, final: boolean) => void;
  58. /**
  59. * Handler for asynchronous data (de)compression streams
  60. * @param err Any error that occurred
  61. * @param data The data output from the stream processor
  62. * @param final Whether this is the final block
  63. */
  64. export declare type AsyncFlateStreamHandler = (err: Error, data: Uint8Array, final: boolean) => void;
  65. /**
  66. * Callback for asynchronous (de)compression methods
  67. * @param err Any error that occurred
  68. * @param data The resulting data. Only present if `err` is null
  69. */
  70. export declare type FlateCallback = (err: Error | string, data: Uint8Array) => void;
  71. interface AsyncOptions {
  72. /**
  73. * Whether or not to "consume" the source data. This will make the typed array/buffer you pass in
  74. * unusable but will increase performance and reduce memory usage.
  75. */
  76. consume?: boolean;
  77. }
  78. /**
  79. * Options for compressing data asynchronously into a DEFLATE format
  80. */
  81. export interface AsyncDeflateOptions extends DeflateOptions, AsyncOptions {
  82. }
  83. /**
  84. * Options for decompressing DEFLATE data asynchronously
  85. */
  86. export interface AsyncInflateOptions extends AsyncOptions {
  87. /**
  88. * The original size of the data. Currently, the asynchronous API disallows
  89. * writing into a buffer you provide; the best you can do is provide the
  90. * size in bytes and be given back a new typed array.
  91. */
  92. size?: number;
  93. }
  94. /**
  95. * Options for compressing data asynchronously into a GZIP format
  96. */
  97. export interface AsyncGzipOptions extends GzipOptions, AsyncOptions {
  98. }
  99. /**
  100. * Options for decompressing GZIP data asynchronously
  101. */
  102. export interface AsyncGunzipOptions extends AsyncOptions {
  103. }
  104. /**
  105. * Options for compressing data asynchronously into a Zlib format
  106. */
  107. export interface AsyncZlibOptions extends ZlibOptions, AsyncOptions {
  108. }
  109. /**
  110. * Options for decompressing Zlib data asynchronously
  111. */
  112. export interface AsyncUnzlibOptions extends AsyncInflateOptions {
  113. }
  114. /**
  115. * A terminable compression/decompression process
  116. */
  117. export interface AsyncTerminable {
  118. /**
  119. * Terminates the worker thread immediately. The callback will not be called.
  120. */
  121. (): void;
  122. }
  123. /**
  124. * Streaming DEFLATE compression
  125. */
  126. export declare class Deflate {
  127. /**
  128. * Creates a DEFLATE stream
  129. * @param opts The compression options
  130. * @param cb The callback to call whenever data is deflated
  131. */
  132. constructor(opts: DeflateOptions, cb?: FlateStreamHandler);
  133. constructor(cb?: FlateStreamHandler);
  134. private o;
  135. private d;
  136. /**
  137. * The handler to call whenever data is available
  138. */
  139. ondata: FlateStreamHandler;
  140. private p;
  141. /**
  142. * Pushes a chunk to be deflated
  143. * @param chunk The chunk to push
  144. * @param final Whether this is the last chunk
  145. */
  146. push(chunk: Uint8Array, final?: boolean): void;
  147. }
  148. /**
  149. * Asynchronous streaming DEFLATE compression
  150. */
  151. export declare class AsyncDeflate {
  152. /**
  153. * The handler to call whenever data is available
  154. */
  155. ondata: AsyncFlateStreamHandler;
  156. /**
  157. * Creates an asynchronous DEFLATE stream
  158. * @param opts The compression options
  159. * @param cb The callback to call whenever data is deflated
  160. */
  161. constructor(opts: DeflateOptions, cb?: AsyncFlateStreamHandler);
  162. /**
  163. * Creates an asynchronous DEFLATE stream
  164. * @param cb The callback to call whenever data is deflated
  165. */
  166. constructor(cb?: AsyncFlateStreamHandler);
  167. /**
  168. * Pushes a chunk to be deflated
  169. * @param chunk The chunk to push
  170. * @param final Whether this is the last chunk
  171. */
  172. push(chunk: Uint8Array, final?: boolean): void;
  173. /**
  174. * A method to terminate the stream's internal worker. Subsequent calls to
  175. * push() will silently fail.
  176. */
  177. terminate: AsyncTerminable;
  178. }
  179. /**
  180. * Asynchronously compresses data with DEFLATE without any wrapper
  181. * @param data The data to compress
  182. * @param opts The compression options
  183. * @param cb The function to be called upon compression completion
  184. * @returns A function that can be used to immediately terminate the compression
  185. */
  186. export declare function deflate(data: Uint8Array, opts: AsyncDeflateOptions, cb: FlateCallback): AsyncTerminable;
  187. /**
  188. * Asynchronously compresses data with DEFLATE without any wrapper
  189. * @param data The data to compress
  190. * @param cb The function to be called upon compression completion
  191. */
  192. export declare function deflate(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  193. /**
  194. * Compresses data with DEFLATE without any wrapper
  195. * @param data The data to compress
  196. * @param opts The compression options
  197. * @returns The deflated version of the data
  198. */
  199. export declare function deflateSync(data: Uint8Array, opts?: DeflateOptions): Uint8Array;
  200. /**
  201. * Streaming DEFLATE decompression
  202. */
  203. export declare class Inflate {
  204. /**
  205. * Creates an inflation stream
  206. * @param cb The callback to call whenever data is inflated
  207. */
  208. constructor(cb?: FlateStreamHandler);
  209. private s;
  210. private o;
  211. private p;
  212. private d;
  213. /**
  214. * The handler to call whenever data is available
  215. */
  216. ondata: FlateStreamHandler;
  217. private e;
  218. private c;
  219. /**
  220. * Pushes a chunk to be inflated
  221. * @param chunk The chunk to push
  222. * @param final Whether this is the final chunk
  223. */
  224. push(chunk: Uint8Array, final?: boolean): void;
  225. }
  226. /**
  227. * Asynchronous streaming DEFLATE decompression
  228. */
  229. export declare class AsyncInflate {
  230. /**
  231. * The handler to call whenever data is available
  232. */
  233. ondata: AsyncFlateStreamHandler;
  234. /**
  235. * Creates an asynchronous inflation stream
  236. * @param cb The callback to call whenever data is deflated
  237. */
  238. constructor(cb?: AsyncFlateStreamHandler);
  239. /**
  240. * Pushes a chunk to be inflated
  241. * @param chunk The chunk to push
  242. * @param final Whether this is the last chunk
  243. */
  244. push(chunk: Uint8Array, final?: boolean): void;
  245. /**
  246. * A method to terminate the stream's internal worker. Subsequent calls to
  247. * push() will silently fail.
  248. */
  249. terminate: AsyncTerminable;
  250. }
  251. /**
  252. * Asynchronously expands DEFLATE data with no wrapper
  253. * @param data The data to decompress
  254. * @param opts The decompression options
  255. * @param cb The function to be called upon decompression completion
  256. * @returns A function that can be used to immediately terminate the decompression
  257. */
  258. export declare function inflate(data: Uint8Array, opts: AsyncInflateOptions, cb: FlateCallback): AsyncTerminable;
  259. /**
  260. * Asynchronously expands DEFLATE data with no wrapper
  261. * @param data The data to decompress
  262. * @param cb The function to be called upon decompression completion
  263. * @returns A function that can be used to immediately terminate the decompression
  264. */
  265. export declare function inflate(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  266. /**
  267. * Expands DEFLATE data with no wrapper
  268. * @param data The data to decompress
  269. * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
  270. * @returns The decompressed version of the data
  271. */
  272. export declare function inflateSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
  273. /**
  274. * Streaming GZIP compression
  275. */
  276. export declare class Gzip {
  277. private c;
  278. private l;
  279. private v;
  280. private o;
  281. /**
  282. * The handler to call whenever data is available
  283. */
  284. ondata: FlateStreamHandler;
  285. /**
  286. * Creates a GZIP stream
  287. * @param opts The compression options
  288. * @param cb The callback to call whenever data is deflated
  289. */
  290. constructor(opts: GzipOptions, cb?: FlateStreamHandler);
  291. /**
  292. * Creates a GZIP stream
  293. * @param cb The callback to call whenever data is deflated
  294. */
  295. constructor(cb?: FlateStreamHandler);
  296. /**
  297. * Pushes a chunk to be GZIPped
  298. * @param chunk The chunk to push
  299. * @param final Whether this is the last chunk
  300. */
  301. push(chunk: Uint8Array, final?: boolean): void;
  302. private p;
  303. }
  304. /**
  305. * Asynchronous streaming GZIP compression
  306. */
  307. export declare class AsyncGzip {
  308. /**
  309. * The handler to call whenever data is available
  310. */
  311. ondata: AsyncFlateStreamHandler;
  312. /**
  313. * Creates an asynchronous GZIP stream
  314. * @param opts The compression options
  315. * @param cb The callback to call whenever data is deflated
  316. */
  317. constructor(opts: GzipOptions, cb?: AsyncFlateStreamHandler);
  318. /**
  319. * Creates an asynchronous GZIP stream
  320. * @param cb The callback to call whenever data is deflated
  321. */
  322. constructor(cb?: AsyncFlateStreamHandler);
  323. /**
  324. * Pushes a chunk to be GZIPped
  325. * @param chunk The chunk to push
  326. * @param final Whether this is the last chunk
  327. */
  328. push(chunk: Uint8Array, final?: boolean): void;
  329. /**
  330. * A method to terminate the stream's internal worker. Subsequent calls to
  331. * push() will silently fail.
  332. */
  333. terminate: AsyncTerminable;
  334. }
  335. /**
  336. * Asynchronously compresses data with GZIP
  337. * @param data The data to compress
  338. * @param opts The compression options
  339. * @param cb The function to be called upon compression completion
  340. * @returns A function that can be used to immediately terminate the compression
  341. */
  342. export declare function gzip(data: Uint8Array, opts: AsyncGzipOptions, cb: FlateCallback): AsyncTerminable;
  343. /**
  344. * Asynchronously compresses data with GZIP
  345. * @param data The data to compress
  346. * @param cb The function to be called upon compression completion
  347. * @returns A function that can be used to immediately terminate the decompression
  348. */
  349. export declare function gzip(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  350. /**
  351. * Compresses data with GZIP
  352. * @param data The data to compress
  353. * @param opts The compression options
  354. * @returns The gzipped version of the data
  355. */
  356. export declare function gzipSync(data: Uint8Array, opts?: GzipOptions): Uint8Array;
  357. /**
  358. * Streaming GZIP decompression
  359. */
  360. export declare class Gunzip {
  361. private v;
  362. private p;
  363. /**
  364. * The handler to call whenever data is available
  365. */
  366. ondata: FlateStreamHandler;
  367. /**
  368. * Creates a GUNZIP stream
  369. * @param cb The callback to call whenever data is inflated
  370. */
  371. constructor(cb?: FlateStreamHandler);
  372. /**
  373. * Pushes a chunk to be GUNZIPped
  374. * @param chunk The chunk to push
  375. * @param final Whether this is the last chunk
  376. */
  377. push(chunk: Uint8Array, final?: boolean): void;
  378. }
  379. /**
  380. * Asynchronous streaming GZIP decompression
  381. */
  382. export declare class AsyncGunzip {
  383. /**
  384. * The handler to call whenever data is available
  385. */
  386. ondata: AsyncFlateStreamHandler;
  387. /**
  388. * Creates an asynchronous GUNZIP stream
  389. * @param cb The callback to call whenever data is deflated
  390. */
  391. constructor(cb: AsyncFlateStreamHandler);
  392. /**
  393. * Pushes a chunk to be GUNZIPped
  394. * @param chunk The chunk to push
  395. * @param final Whether this is the last chunk
  396. */
  397. push(chunk: Uint8Array, final?: boolean): void;
  398. /**
  399. * A method to terminate the stream's internal worker. Subsequent calls to
  400. * push() will silently fail.
  401. */
  402. terminate: AsyncTerminable;
  403. }
  404. /**
  405. * Asynchronously expands GZIP data
  406. * @param data The data to decompress
  407. * @param opts The decompression options
  408. * @param cb The function to be called upon decompression completion
  409. * @returns A function that can be used to immediately terminate the decompression
  410. */
  411. export declare function gunzip(data: Uint8Array, opts: AsyncGunzipOptions, cb: FlateCallback): AsyncTerminable;
  412. /**
  413. * Asynchronously expands GZIP data
  414. * @param data The data to decompress
  415. * @param cb The function to be called upon decompression completion
  416. * @returns A function that can be used to immediately terminate the decompression
  417. */
  418. export declare function gunzip(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  419. /**
  420. * Expands GZIP data
  421. * @param data The data to decompress
  422. * @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.
  423. * @returns The decompressed version of the data
  424. */
  425. export declare function gunzipSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
  426. /**
  427. * Streaming Zlib compression
  428. */
  429. export declare class Zlib {
  430. private c;
  431. private v;
  432. private o;
  433. /**
  434. * The handler to call whenever data is available
  435. */
  436. ondata: FlateStreamHandler;
  437. /**
  438. * Creates a Zlib stream
  439. * @param opts The compression options
  440. * @param cb The callback to call whenever data is deflated
  441. */
  442. constructor(opts: ZlibOptions, cb?: FlateStreamHandler);
  443. /**
  444. * Creates a Zlib stream
  445. * @param cb The callback to call whenever data is deflated
  446. */
  447. constructor(cb?: FlateStreamHandler);
  448. /**
  449. * Pushes a chunk to be zlibbed
  450. * @param chunk The chunk to push
  451. * @param final Whether this is the last chunk
  452. */
  453. push(chunk: Uint8Array, final?: boolean): void;
  454. private p;
  455. }
  456. /**
  457. * Asynchronous streaming Zlib compression
  458. */
  459. export declare class AsyncZlib {
  460. /**
  461. * The handler to call whenever data is available
  462. */
  463. ondata: AsyncFlateStreamHandler;
  464. /**
  465. * Creates an asynchronous DEFLATE stream
  466. * @param opts The compression options
  467. * @param cb The callback to call whenever data is deflated
  468. */
  469. constructor(opts: ZlibOptions, cb?: AsyncFlateStreamHandler);
  470. /**
  471. * Creates an asynchronous DEFLATE stream
  472. * @param cb The callback to call whenever data is deflated
  473. */
  474. constructor(cb?: AsyncFlateStreamHandler);
  475. /**
  476. * Pushes a chunk to be deflated
  477. * @param chunk The chunk to push
  478. * @param final Whether this is the last chunk
  479. */
  480. push(chunk: Uint8Array, final?: boolean): void;
  481. /**
  482. * A method to terminate the stream's internal worker. Subsequent calls to
  483. * push() will silently fail.
  484. */
  485. terminate: AsyncTerminable;
  486. }
  487. /**
  488. * Asynchronously compresses data with Zlib
  489. * @param data The data to compress
  490. * @param opts The compression options
  491. * @param cb The function to be called upon compression completion
  492. */
  493. export declare function zlib(data: Uint8Array, opts: AsyncZlibOptions, cb: FlateCallback): AsyncTerminable;
  494. /**
  495. * Asynchronously compresses data with Zlib
  496. * @param data The data to compress
  497. * @param cb The function to be called upon compression completion
  498. * @returns A function that can be used to immediately terminate the compression
  499. */
  500. export declare function zlib(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  501. /**
  502. * Compress data with Zlib
  503. * @param data The data to compress
  504. * @param opts The compression options
  505. * @returns The zlib-compressed version of the data
  506. */
  507. export declare function zlibSync(data: Uint8Array, opts?: ZlibOptions): Uint8Array;
  508. /**
  509. * Streaming Zlib decompression
  510. */
  511. export declare class Unzlib {
  512. private v;
  513. private p;
  514. /**
  515. * The handler to call whenever data is available
  516. */
  517. ondata: FlateStreamHandler;
  518. /**
  519. * Creates a Zlib decompression stream
  520. * @param cb The callback to call whenever data is inflated
  521. */
  522. constructor(cb?: FlateStreamHandler);
  523. /**
  524. * Pushes a chunk to be unzlibbed
  525. * @param chunk The chunk to push
  526. * @param final Whether this is the last chunk
  527. */
  528. push(chunk: Uint8Array, final?: boolean): void;
  529. }
  530. /**
  531. * Asynchronous streaming Zlib decompression
  532. */
  533. export declare class AsyncUnzlib {
  534. /**
  535. * The handler to call whenever data is available
  536. */
  537. ondata: AsyncFlateStreamHandler;
  538. /**
  539. * Creates an asynchronous Zlib decompression stream
  540. * @param cb The callback to call whenever data is deflated
  541. */
  542. constructor(cb?: AsyncFlateStreamHandler);
  543. /**
  544. * Pushes a chunk to be decompressed from Zlib
  545. * @param chunk The chunk to push
  546. * @param final Whether this is the last chunk
  547. */
  548. push(chunk: Uint8Array, final?: boolean): void;
  549. /**
  550. * A method to terminate the stream's internal worker. Subsequent calls to
  551. * push() will silently fail.
  552. */
  553. terminate: AsyncTerminable;
  554. }
  555. /**
  556. * Asynchronously expands Zlib data
  557. * @param data The data to decompress
  558. * @param opts The decompression options
  559. * @param cb The function to be called upon decompression completion
  560. * @returns A function that can be used to immediately terminate the decompression
  561. */
  562. export declare function unzlib(data: Uint8Array, opts: AsyncGunzipOptions, cb: FlateCallback): AsyncTerminable;
  563. /**
  564. * Asynchronously expands Zlib data
  565. * @param data The data to decompress
  566. * @param cb The function to be called upon decompression completion
  567. * @returns A function that can be used to immediately terminate the decompression
  568. */
  569. export declare function unzlib(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  570. /**
  571. * Expands Zlib data
  572. * @param data The data to decompress
  573. * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
  574. * @returns The decompressed version of the data
  575. */
  576. export declare function unzlibSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
  577. export { gzip as compress, AsyncGzip as AsyncCompress };
  578. export { gzipSync as compressSync, Gzip as Compress };
  579. /**
  580. * Streaming GZIP, Zlib, or raw DEFLATE decompression
  581. */
  582. export declare class Decompress {
  583. private G;
  584. private I;
  585. private Z;
  586. /**
  587. * Creates a decompression stream
  588. * @param cb The callback to call whenever data is decompressed
  589. */
  590. constructor(cb?: FlateStreamHandler);
  591. private s;
  592. /**
  593. * The handler to call whenever data is available
  594. */
  595. ondata: FlateStreamHandler;
  596. private p;
  597. /**
  598. * Pushes a chunk to be decompressed
  599. * @param chunk The chunk to push
  600. * @param final Whether this is the last chunk
  601. */
  602. push(chunk: Uint8Array, final?: boolean): void;
  603. }
  604. /**
  605. * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
  606. */
  607. export declare class AsyncDecompress {
  608. private G;
  609. private I;
  610. private Z;
  611. /**
  612. * Creates an asynchronous decompression stream
  613. * @param cb The callback to call whenever data is decompressed
  614. */
  615. constructor(cb?: AsyncFlateStreamHandler);
  616. /**
  617. * The handler to call whenever data is available
  618. */
  619. ondata: AsyncFlateStreamHandler;
  620. /**
  621. * Pushes a chunk to be decompressed
  622. * @param chunk The chunk to push
  623. * @param final Whether this is the last chunk
  624. */
  625. push(chunk: Uint8Array, final?: boolean): void;
  626. }
  627. /**
  628. * Asynchrononously expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
  629. * @param data The data to decompress
  630. * @param opts The decompression options
  631. * @param cb The function to be called upon decompression completion
  632. * @returns A function that can be used to immediately terminate the decompression
  633. */
  634. export declare function decompress(data: Uint8Array, opts: AsyncInflateOptions, cb: FlateCallback): AsyncTerminable;
  635. /**
  636. * Asynchrononously expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
  637. * @param data The data to decompress
  638. * @param cb The function to be called upon decompression completion
  639. * @returns A function that can be used to immediately terminate the decompression
  640. */
  641. export declare function decompress(data: Uint8Array, cb: FlateCallback): AsyncTerminable;
  642. /**
  643. * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
  644. * @param data The data to decompress
  645. * @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
  646. * @returns The decompressed version of the data
  647. */
  648. export declare function decompressSync(data: Uint8Array, out?: Uint8Array): Uint8Array;
  649. /**
  650. * Options for creating a ZIP archive
  651. */
  652. export interface ZipOptions extends DeflateOptions, Pick<GzipOptions, 'mtime'> {
  653. }
  654. /**
  655. * Options for asynchronously creating a ZIP archive
  656. */
  657. export interface AsyncZipOptions extends AsyncDeflateOptions, Pick<AsyncGzipOptions, 'mtime'> {
  658. }
  659. /**
  660. * Options for asynchronously expanding a ZIP archive
  661. */
  662. export interface AsyncUnzipOptions extends AsyncOptions {
  663. }
  664. /**
  665. * A file that can be used to create a ZIP archive
  666. */
  667. export declare type ZippableFile = Uint8Array | [Uint8Array, ZipOptions];
  668. /**
  669. * A file that can be used to asynchronously create a ZIP archive
  670. */
  671. export declare type AsyncZippableFile = Uint8Array | [Uint8Array, AsyncZipOptions];
  672. /**
  673. * The complete directory structure of a ZIPpable archive
  674. */
  675. export interface Zippable extends Record<string, Zippable | ZippableFile> {
  676. }
  677. /**
  678. * The complete directory structure of an asynchronously ZIPpable archive
  679. */
  680. export interface AsyncZippable extends Record<string, AsyncZippable | AsyncZippableFile> {
  681. }
  682. /**
  683. * An unzipped archive. The full path of each file is used as the key,
  684. * and the file is the value
  685. */
  686. export interface Unzipped extends Record<string, Uint8Array> {
  687. }
  688. /**
  689. * Callback for asynchronous ZIP decompression
  690. * @param err Any error that occurred
  691. * @param data The decompressed ZIP archive
  692. */
  693. export declare type UnzipCallback = (err: Error | string, data: Unzipped) => void;
  694. /**
  695. * Converts a string into a Uint8Array for use with compression/decompression methods
  696. * @param str The string to encode
  697. * @param latin1 Whether or not to interpret the data as Latin-1. This should
  698. * not need to be true unless decoding a binary string.
  699. * @returns The string encoded in UTF-8/Latin-1 binary
  700. */
  701. export declare function strToU8(str: string, latin1?: boolean): Uint8Array;
  702. /**
  703. * Converts a Uint8Array to a string
  704. * @param dat The data to decode to string
  705. * @param latin1 Whether or not to interpret the data as Latin-1. This should
  706. * not need to be true unless encoding to binary string.
  707. * @returns The original UTF-8/Latin-1 string
  708. */
  709. export declare function strFromU8(dat: Uint8Array, latin1?: boolean): string;
  710. /**
  711. * Asynchronously creates a ZIP file
  712. * @param data The directory structure for the ZIP archive
  713. * @param opts The main options, merged with per-file options
  714. * @param cb The callback to call with the generated ZIP archive
  715. * @returns A function that can be used to immediately terminate the compression
  716. */
  717. export declare function zip(data: AsyncZippable, opts: AsyncZipOptions, cb: FlateCallback): AsyncTerminable;
  718. /**
  719. * Asynchronously creates a ZIP file
  720. * @param data The directory structure for the ZIP archive
  721. * @param cb The callback to call with the generated ZIP archive
  722. * @returns A function that can be used to immediately terminate the compression
  723. */
  724. export declare function zip(data: AsyncZippable, cb: FlateCallback): AsyncTerminable;
  725. /**
  726. * Synchronously creates a ZIP file. Prefer using `zip` for better performance
  727. * with more than one file.
  728. * @param data The directory structure for the ZIP archive
  729. * @param opts The main options, merged with per-file options
  730. * @returns The generated ZIP archive
  731. */
  732. export declare function zipSync(data: Zippable, opts?: ZipOptions): Uint8Array;
  733. /**
  734. * Asynchronously decompresses a ZIP archive
  735. * @param data The raw compressed ZIP file
  736. * @param cb The callback to call with the decompressed files
  737. * @returns A function that can be used to immediately terminate the unzipping
  738. */
  739. export declare function unzip(data: Uint8Array, cb: UnzipCallback): AsyncTerminable;
  740. /**
  741. * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
  742. * performance with more than one file.
  743. * @param data The raw compressed ZIP file
  744. * @returns The decompressed files
  745. */
  746. export declare function unzipSync(data: Uint8Array): Unzipped;