Count Bytes In File Stream
NodeJS
Hard
3 views
Problem Description
Count bytes in a file using createReadStream.
Input Format
stdin: file path.
Output Format
Print integer bytes.
Constraints
Sum chunk lengths.
Official Solution
const fs = require('fs');
const p = fs.readFileSync(0, 'utf8').trim();
if (!p) process.exit(0);
let bytes = 0;
const r = fs.createReadStream(p);
r.on('data', (c) => { bytes += c.length; });
r.on('error', () => console.log(0));
r.on('end', () => console.log(bytes));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!