@utilx/stream v0.0.22
stream-utils
npm install @typeshell/stream-utilsReadableX
Provide stream enhance class called ReadnableX, you could enhance your stream.Readable by calling:
const enhance_readable_obj = ReadableX.wrap(your_readable_obj)What can you do in ReadableX:
- hash, encryption
- zip, gzip, compress and decompress facility
- easy to convert to string, lines, and other forms easy to process.
echo: string => stream
echo is the simplest function and display our enhanced Readable, let's see what can we do.
const md5_str1 = await echo("hello world").md5()
const md5_str2 = echo("hello world").md5$() // special for echo
// Now you have a zip file, one file called default inside, content is "hello world"
await echo("hello world").zip1ToDisk("a.zip")dump: stream => dump
Here is the way to convert stream.Readable to string
dumps(fs.createReadaStream("input1"))The dumps() function is embeded inside our ReadableX
cat("input1").dumps()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 out3tee
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"])6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago