Using Node.js v5.1.0, I'm trying to determine the content length of a buffer. As such, I'm doing this:
Buffer.byteLength(self.data, 'utf8')
where self.data
looks like this:
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 f0 00 f0 00 00 ff db 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0c 08 07 07 07 07 0f 0b 0b 09 ... >
The image I'm loading is 109,055 bytes (111 KB on disk) on the file system (OS X), but my content length calculation is returning 198,147 bytes. If I set the encoding to ascii
, it returns 104,793 bytes. Much closer, but still not correct.
Am I calculating this correctly? Do I need to do something to the buffer to get it to return the correct value? If I'm doing it right, why the discrepancy? If I'm doing it wrong, well, please share ;)