Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.d.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /// <reference types="node" />
  2. import { EventEmitter } from 'events'
  3. import { Stream } from 'stream'
  4. declare namespace Minipass {
  5. type Encoding = BufferEncoding | 'buffer' | null
  6. interface Writable extends EventEmitter {
  7. end(): any
  8. write(chunk: any, ...args: any[]): any
  9. }
  10. interface Readable extends EventEmitter {
  11. pause(): any
  12. resume(): any
  13. pipe(): any
  14. }
  15. interface Pipe<R, W> {
  16. src: Minipass<R, W>
  17. dest: Writable
  18. opts: PipeOptions
  19. }
  20. type DualIterable<T> = Iterable<T> & AsyncIterable<T>
  21. type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string
  22. type BufferOrString = Buffer | string
  23. interface StringOptions {
  24. encoding: BufferEncoding
  25. objectMode?: boolean
  26. async?: boolean
  27. }
  28. interface BufferOptions {
  29. encoding?: null | 'buffer'
  30. objectMode?: boolean
  31. async?: boolean
  32. }
  33. interface ObjectModeOptions {
  34. objectMode: true
  35. async?: boolean
  36. }
  37. interface PipeOptions {
  38. end?: boolean
  39. proxyErrors?: boolean
  40. }
  41. type Options<T> = T extends string
  42. ? StringOptions
  43. : T extends Buffer
  44. ? BufferOptions
  45. : ObjectModeOptions
  46. }
  47. declare class Minipass<
  48. RType extends any = Buffer,
  49. WType extends any = RType extends Minipass.BufferOrString
  50. ? Minipass.ContiguousData
  51. : RType
  52. >
  53. extends Stream
  54. implements Minipass.DualIterable<RType>
  55. {
  56. static isStream(stream: any): stream is Minipass.Readable | Minipass.Writable
  57. readonly bufferLength: number
  58. readonly flowing: boolean
  59. readonly writable: boolean
  60. readonly readable: boolean
  61. readonly paused: boolean
  62. readonly emittedEnd: boolean
  63. readonly destroyed: boolean
  64. /**
  65. * Not technically private or readonly, but not safe to mutate.
  66. */
  67. private readonly buffer: RType[]
  68. private readonly pipes: Minipass.Pipe<RType, WType>[]
  69. /**
  70. * Technically writable, but mutating it can change the type,
  71. * so is not safe to do in TypeScript.
  72. */
  73. readonly objectMode: boolean
  74. async: boolean
  75. /**
  76. * Note: encoding is not actually read-only, and setEncoding(enc)
  77. * exists. However, this type definition will insist that TypeScript
  78. * programs declare the type of a Minipass stream up front, and if
  79. * that type is string, then an encoding MUST be set in the ctor. If
  80. * the type is Buffer, then the encoding must be missing, or set to
  81. * 'buffer' or null. If the type is anything else, then objectMode
  82. * must be set in the constructor options. So there is effectively
  83. * no allowed way that a TS program can set the encoding after
  84. * construction, as doing so will destroy any hope of type safety.
  85. * TypeScript does not provide many options for changing the type of
  86. * an object at run-time, which is what changing the encoding does.
  87. */
  88. readonly encoding: Minipass.Encoding
  89. // setEncoding(encoding: Encoding): void
  90. // Options required if not reading buffers
  91. constructor(
  92. ...args: RType extends Buffer
  93. ? [] | [Minipass.Options<RType>]
  94. : [Minipass.Options<RType>]
  95. )
  96. write(chunk: WType, cb?: () => void): boolean
  97. write(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): boolean
  98. read(size?: number): RType
  99. end(cb?: () => void): this
  100. end(chunk: any, cb?: () => void): this
  101. end(chunk: any, encoding?: Minipass.Encoding, cb?: () => void): this
  102. pause(): void
  103. resume(): void
  104. promise(): Promise<void>
  105. collect(): Promise<RType[]>
  106. concat(): RType extends Minipass.BufferOrString ? Promise<RType> : never
  107. destroy(er?: any): void
  108. pipe<W extends Minipass.Writable>(dest: W, opts?: Minipass.PipeOptions): W
  109. unpipe<W extends Minipass.Writable>(dest: W): void
  110. /**
  111. * alias for on()
  112. */
  113. addEventHandler(event: string, listener: (...args: any[]) => any): this
  114. on(event: string, listener: (...args: any[]) => any): this
  115. on(event: 'data', listener: (chunk: RType) => any): this
  116. on(event: 'error', listener: (error: any) => any): this
  117. on(
  118. event:
  119. | 'readable'
  120. | 'drain'
  121. | 'resume'
  122. | 'end'
  123. | 'prefinish'
  124. | 'finish'
  125. | 'close',
  126. listener: () => any
  127. ): this
  128. [Symbol.iterator](): Iterator<RType>
  129. [Symbol.asyncIterator](): AsyncIterator<RType>
  130. }
  131. export = Minipass