is-stream

  • Version 4.0.1
  • Published
  • 7.62 kB
  • No dependencies
  • MIT license

Install

npm i is-stream
yarn add is-stream
pnpm add is-stream

Overview

Check if something is a Node.js stream

Index

Functions

function isDuplexStream

isDuplexStream: (stream: unknown, options?: Options) => stream is DuplexStream;
  • Returns

    Whether stream is a [stream.Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex).

    Example 1

    import {Duplex as DuplexStream} from 'node:stream';
    import {isDuplexStream} from 'is-stream';
    isDuplexStream(new DuplexStream());
    //=> true

function isReadableStream

isReadableStream: (
stream: unknown,
options?: Options
) => stream is ReadableStream;
  • Returns

    Whether stream is 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).

    Example 1

    import fs from 'node:fs';
    import {isReadableStream} from 'is-stream';
    isReadableStream(fs.createReadStream('unicorn.png'));
    //=> true

function isStream

isStream: (stream: unknown, options?: Options) => stream is Stream;
  • Returns

    Whether stream is a [Stream](https://nodejs.org/api/stream.html#stream_stream).

    Example 1

    import fs from 'node:fs';
    import {isStream} from 'is-stream';
    isStream(fs.createReadStream('unicorn.png'));
    //=> true
    isStream({});
    //=> false

function isTransformStream

isTransformStream: (
stream: unknown,
options?: Options
) => stream is TransformStream;
  • Returns

    Whether stream is a [stream.Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform).

    Example 1

    import fs from 'node:fs';
    import StringifyStream from 'streaming-json-stringify';
    import {isTransformStream} from 'is-stream';
    isTransformStream(StringifyStream());
    //=> true

function isWritableStream

isWritableStream: (
stream: unknown,
options?: Options
) => stream is WritableStream;
  • Returns

    Whether stream is 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).

    Example 1

    import fs from 'node:fs';
    import {isWritableStream} from 'is-stream';
    isWritableStream(fs.createWriteStrem('unicorn.txt'));
    //=> true

Type Aliases

type Options

type Options = {
/**
When this option is `true`, the method returns `false` if the stream has already been closed.
@default true
*/
checkOpen?: boolean;
};

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (5)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/is-stream.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/is-stream)
    • HTML
      <a href="https://www.jsdocs.io/package/is-stream"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>