PassThrough Logger
NodeJS
Medium
3 views
Problem Description
Use PassThrough to tap into a stream and count bytes.
Input Format
stdin: any text.
Output Format
Print integer bytes.
Constraints
Count bytes flowing through.
Official Solution
const { PassThrough } = require('stream');
let bytes = 0;
const tap = new PassThrough();
tap.on('data', (c) => { bytes += c.length; });
process.stdin.pipe(tap).resume();
process.stdin.on('end', () => console.log(bytes));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!