index.d.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {type Readable} from 'node:stream';
  2. /**
  3. Merges an array of [readable streams](https://nodejs.org/api/stream.html#readable-streams) and returns a new readable stream that emits data from the individual streams as it arrives.
  4. If you provide an empty array, it returns an already-ended stream.
  5. @example
  6. ```
  7. import mergeStreams from '@sindresorhus/merge-streams';
  8. const stream = mergeStreams([streamA, streamB]);
  9. for await (const chunk of stream) {
  10. console.log(chunk);
  11. //=> 'A1'
  12. //=> 'B1'
  13. //=> 'A2'
  14. //=> 'B2'
  15. }
  16. ```
  17. */
  18. export default function mergeStreams(streams: Readable[]): MergedStream;
  19. /**
  20. A single stream combining the output of multiple streams.
  21. */
  22. export class MergedStream extends Readable {
  23. /**
  24. Pipe a new readable stream.
  25. Throws if `MergedStream` has already ended.
  26. */
  27. add(stream: Readable): void;
  28. /**
  29. Unpipe a stream previously added using either `mergeStreams(streams)` or `MergedStream.add(stream)`.
  30. Returns `false` if the stream was not previously added, or if it was already removed by `MergedStream.remove(stream)`.
  31. The removed stream is not automatically ended.
  32. */
  33. remove(stream: Readable): boolean;
  34. }