Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJs get size of variable in bytes

I have a variable 'img' which is an image file that has been loaded via:

var img = fs.readFileSync('./tmp.png');

How do I determine how many bytes the 'img' variable is?

like image 971
greatwitenorth Avatar asked Apr 19 '12 19:04

greatwitenorth


1 Answers

Like img is a buffer, you can simply use img.length, it will give you the size in octets (byte of 8bits)

like image 71
Tronix117 Avatar answered Oct 04 '22 00:10

Tronix117