Files
30-seconds-of-code/snippets/js/s/is-stream.md
2023-05-07 16:07:29 +03:00

551 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Value is stream snippet javascript
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