index.d.ts 4.5 KB

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