node_stream_zip.d.ts 4.4 KB

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