I get files as byte buffers and cannot use fs.stat() method. So I am try to use buf.length but this length refers to the amount of memory allocated for the buffer object and not actually the content size. For example I have file with with size 22,449 bytes. buf.length returns for 39804 for it.
To check the buffer window, multiply the bit rate (bits per second) by the buffer window (in seconds) and divide by 1000 to get the size, in bits, of the buffer for the stream.
In Node. js, the Buffer. toString() method is used to decode or convert a buffer to a string, according to the specified character encoding type. Converting a buffer to a string is known as encoding, and converting a string to a buffer is known as decoding.
You need byteLength
:
var buff = fs.readFileSync(__dirname + '/test.txt'); console.log(Buffer.byteLength(buff));
For node 0.10.21 you can try this:
console.log(buff.toString().length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With