javascript - Buffer.byteLength returning drastically different byte length -
using node.js v5.1.0, i'm trying determine content length of buffer. such, i'm doing this:
buffer.bytelength(self.data, 'utf8')
where self.data
looks 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 109,055 bytes (111 kb on disk) on file system (os x), content length calculation returning 198,147 bytes. if set encoding ascii
, returns 104,793 bytes. closer, still not correct.
am calculating correctly? need buffer return correct value? if i'm doing right, why discrepancy? if i'm doing wrong, well, please share ;)
as explained in documentation, buffer.bytelength()
returns byte length of string assuming specific encoding.
the buffer
type arraybuffer
means it's length can acquired via bytelength
property. also, node's implementation adds length
property provides same length.
Comments
Post a Comment