index.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { ReadStream, WriteStream } from 'fs'
  2. type sourceType = string | Buffer | ReadStream
  3. type destType = string | WriteStream
  4. interface streamEntryOpts {
  5. relativePath?: string
  6. ignoreBase?: boolean
  7. size?: number
  8. suppressSizeWarning?: boolean
  9. }
  10. interface streamHeader {
  11. type: 'file' | 'directory',
  12. name: string
  13. }
  14. interface streamHeaderWithMode {
  15. type: 'file' | 'directory',
  16. name: string
  17. mode: number
  18. }
  19. export namespace gzip {
  20. function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
  21. function uncompress(source: sourceType, dest: destType, opts?: any): Promise<void>
  22. function decompress(source: sourceType, dest: destType, opts?: any): Promise<void>
  23. export class FileStream extends ReadStream {
  24. constructor(opts?: {
  25. zlib?: object,
  26. source: sourceType
  27. });
  28. }
  29. export class UncompressStream extends WriteStream {
  30. constructor(opts?: {
  31. zlib?: object,
  32. source: sourceType
  33. });
  34. on(event: string, listener: (...args: any[]) => void): this
  35. on(event: 'error', listener: (err: Error) => void): this
  36. }
  37. }
  38. export namespace tar {
  39. function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
  40. function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
  41. function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
  42. function decompress(source: sourceType, dest: string, opts?: any): Promise<void>
  43. export class Stream extends ReadStream {
  44. constructor();
  45. addEntry(entry: string, opts?: streamEntryOpts): void
  46. addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
  47. }
  48. export class FileStream extends ReadStream {
  49. constructor(opts?: {
  50. relativePath?: string,
  51. size?: number,
  52. suppressSizeWarning?: boolean,
  53. source?: sourceType
  54. });
  55. }
  56. export class UncompressStream extends WriteStream {
  57. constructor(opts?: {
  58. source: sourceType
  59. });
  60. on(event: string, listener: (...args: any[]) => void): this
  61. on(event: 'entry', listener: (header: streamHeaderWithMode, stream: ReadStream, next: () => void) => void): this
  62. on(event: 'finish', listener: () => void): this
  63. on(event: 'error', listener: (err: Error) => void): this
  64. }
  65. }
  66. export namespace tgz {
  67. function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
  68. function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
  69. function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
  70. function decompress(source: sourceType, dest: string, opts?: any): Promise<void>
  71. export class Stream extends ReadStream {
  72. constructor();
  73. addEntry(entry: string, opts?: streamEntryOpts): void
  74. addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
  75. }
  76. export class FileStream extends ReadStream {
  77. constructor(opts?: {
  78. relativePath?: string,
  79. size?: number,
  80. suppressSizeWarning?: boolean,
  81. zlib?: object,
  82. source?: sourceType
  83. });
  84. }
  85. export class UncompressStream extends WriteStream {
  86. constructor(opts?: {
  87. source?: sourceType,
  88. strip?: number
  89. });
  90. on(event: string, listener: (...args: any[]) => void): this
  91. on(event: 'entry', listener: (header: streamHeaderWithMode, stream: ReadStream, next: () => void) => void): this
  92. on(event: 'finish', listener: () => void): this
  93. on(event: 'error', listener: (err: Error) => void): this
  94. }
  95. }
  96. export namespace zip {
  97. function compressFile(source: sourceType, dest: destType, opts?: any): Promise<void>
  98. function compressDir(source: sourceType, dest: destType, opts?: any): Promise<void>
  99. function uncompress(source: sourceType, dest: string, opts?: any): Promise<void>
  100. function decompress(source: sourceType, dest: string, opts?: any): Promise<void>
  101. export class Stream extends ReadStream {
  102. constructor();
  103. addEntry(entry: string, opts?: streamEntryOpts): void
  104. addEntry(entry: Buffer | ReadStream, opts: streamEntryOpts): void
  105. }
  106. export class FileStream extends ReadStream {
  107. /**
  108. * If opts.source is a file path, opts.relativePath is optional, otherwise it's required.
  109. *
  110. * @param opts
  111. */
  112. constructor(opts?: {
  113. relativePath?: string,
  114. yazl?: object,
  115. source: string
  116. } | {
  117. relativePath: string,
  118. yazl?: object,
  119. source?: Buffer | ReadStream
  120. });
  121. }
  122. export class UncompressStream extends WriteStream {
  123. constructor(opts?: {
  124. source?: sourceType,
  125. strip?: number,
  126. zipFileNameEncoding?: string
  127. });
  128. on(event: string, listener: (...args: any[]) => void): this
  129. on(event: 'entry', listener: (header: streamHeaderWithMode, stream: ReadStream, next: () => void) => void): this
  130. on(event: 'finish', listener: () => void): this
  131. on(event: 'error', listener: (err: Error) => void): this
  132. }
  133. }