PassThrough Logger

PassThrough Logger

Medium NodeJS Streams & Buffers 30 views
Explanation Complexity

Problem Statement

Use PassThrough to tap into a stream and count bytes.

Input Format

stdin: any text.

Output Format

Print integer bytes.

Example

meetcode
7

Constraints

Count bytes flowing through.

Input / Output Format

Input Format
stdin: any text.
Output Format
Print integer bytes.
Constraints
Count bytes flowing through.

Examples

Input:
meetcode
Output:
7

Example Solution (Public)

NodeJS
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));

Official Solution Code

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));
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.