Files
30-seconds-of-code/snippets/is-stream.md
2023-04-28 22:29:23 +03:00

530 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Value is stream snippet
node
type
mountain-lake-cottage-2 2020-10-20T23:02:01+03:00

Checks if the given argument is a stream.

  • Check if the value is different from null.
  • Use typeof to check if the value is of type object and the pipe property is of type function.
const isStream = val =>
  val !== null && typeof val === 'object' && typeof val.pipe === 'function';
const fs = require('fs');

isStream(fs.createReadStream('test.txt')); // true