市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

  1. # is-stream
  2. > Check if something is a [Node.js stream](https://nodejs.org/api/stream.html)
  3. ## Install
  4. ```sh
  5. npm install is-stream
  6. ```
  7. ## Usage
  8. ```js
  9. import fs from 'node:fs';
  10. import {isStream} from 'is-stream';
  11. isStream(fs.createReadStream('unicorn.png'));
  12. //=> true
  13. isStream({});
  14. //=> false
  15. ```
  16. ## API
  17. ### isStream(stream, options?)
  18. Returns a `boolean` for whether it's a [`Stream`](https://nodejs.org/api/stream.html#stream_stream).
  19. ### isWritableStream(stream, options?)
  20. Returns a `boolean` for whether it's a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable), an [`http.OutgoingMessage`](https://nodejs.org/api/http.html#class-httpoutgoingmessage), an [`http.ServerResponse`](https://nodejs.org/api/http.html#class-httpserverresponse) or an [`http.ClientRequest`](https://nodejs.org/api/http.html#class-httpserverresponse).
  21. ### isReadableStream(stream, options?)
  22. Returns a `boolean` for whether it's a [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable) or an [`http.IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage).
  23. ### isDuplexStream(stream, options?)
  24. Returns a `boolean` for whether it's a [`stream.Duplex`](https://nodejs.org/api/stream.html#stream_class_stream_duplex).
  25. ### isTransformStream(stream, options?)
  26. Returns a `boolean` for whether it's a [`stream.Transform`](https://nodejs.org/api/stream.html#stream_class_stream_transform).
  27. ### Options
  28. #### checkOpen
  29. Type: `boolean`\
  30. Default: `true`
  31. When this option is `true`, the method returns `false` if the stream has already been closed.
  32. ## Related
  33. - [is-file-stream](https://github.com/jamestalmage/is-file-stream) - Detect if a stream is a file stream