@typeshell/stream-utils
v0.0.8
Published
Downloads
1
Readme
stream-utils
npm install @typeshell/stream-utils
Provide stream enhance function
tee And cat
More powerfule replacement for fs.createWriteStream()
and fs.createReadStream()
.
Together it could write code with great simplicity and rich expressiveness
cat("input1").tee("out1", "out2", "out3")
// cat input1 | tee out1 out2 out3
tee
tee is a more powerful replacement for fs.createWriteStream()
fs.createReadStream("input1").pipe(tee(process.stdout, "out1", "out2", "out3"))
If you want to append the new content to out2 and out 3, you could using,
fs.createReadStream("input1").pipe(tee(process.stdout, "out1", ["out2"], ["out3"]))
cat
cat is a more powerful replacement for fs.createReadStream()
// Native Readable.pipe could provide one argument
cat("input1", "input2").pipe(process.stdout)
// Recommend using .tee function for multiple outputs
cat("input1", "input2").tee(process.stdout, "out1", ["out2"], ["out3"])
with string
toString
Here is the way to convert stream.Readable to string
toString(fs.createReadaStream("input1"))
If you are using cat
cat("input1").toString()
fromString
If you want to convert string to stream,
fromString("hello world")