0

Please help me in this question I'm not getting it

write a node.js code snippet to read the large data file (a text file available in the same directory) using streams, and logs the sizes/length of chunks of data read, to the console. I tried this one but the test cases are not getting passed var fs = require("fs"); var readStream = fs.createReadStream("dataFile.txt"); readStream .on("data", function(data) { var chunk = data.toString(); console.log(chunk.length); });

12th Jul 2019, 10:50 AM
Я. ♨
Я. ♨ - avatar
9 Réponses
+ 3
require path
12th Jul 2019, 10:58 AM
Gordon
Gordon - avatar
+ 3
The question is a bit tricky but if you read it twice you will understand te question. Here's the solution: const fs = require('fs'); let readerStream = fs.createReadStream('./Node-stream-handson/data_file.txt'); readerStream.setEncoding('UTF8'); readerStream.on('data',(chunk) => { console.log(chunk.length); });
27th Nov 2020, 7:35 PM
Mia Khalifa
+ 1
i think it's means how many bytes, like 8kb, 1mb, etc
12th Jul 2019, 11:05 AM
Gordon
Gordon - avatar
0
@Gordon when I print the text on console then the data is printing console.log(chunk); but I did not understand what exactly the question is asking it's saying "logs the sizes/length of chunks of data read, to the console." here I will print the length only or anything else too
12th Jul 2019, 11:04 AM
Я. ♨
Я. ♨ - avatar
0
how can i get it using "chunk.length" or any other method
12th Jul 2019, 11:13 AM
Я. ♨
Я. ♨ - avatar
0
Did you solve this?Having same issue.
24th Apr 2020, 9:20 PM
Sandra Toledo Granados
Sandra Toledo Granados - avatar
- 1
var fs = require("fs"); var readStream = fs.createReadStream("Node-stream-handson/data_file.txt"); readStream.on("data", function(data) { var chunk = data.toString(); const fileSizeInBytes = chunk.length; const fileSizeInMegabytes = fileSizeInBytes / 1000000.0; console.log(fileSizeInMegabytes); }); tried this one too
12th Jul 2019, 11:19 AM
Я. ♨
Я. ♨ - avatar
- 1
Here, the problem is with checking code logic developer has written. I will suggest to create new file by command
gt; touch App.js and put following code into it var fs = require("fs"); var readStream = fs.createReadStream("dataFile.txt"); readStream .on("data", function(data) { var chunk = data.toString(); console.log(chunk.length); }); It will work now Don't thanks me.
25th Jul 2019, 12:46 PM
SUDARSHAN BHALERAO
SUDARSHAN BHALERAO - avatar