NodeJS Buffer string conversions

node v8.17.0
version: master
endpointsharetweet
const bufferUtf8 = Buffer.from('1234', 'utf8')
const bufferUtf16 = Buffer.from('1234', 'utf16le')
const bufferHex = Buffer.from('1234', 'hex')
bufferUtf8.toString('binary')
bufferUtf8.toString('latin1')
bufferUtf16.toString('binary')
Above, may be hard to read at first. We have a string with character '1' (31) then escape sequence \u0000 for 00, then '2' for (32) then \u0000 for 00, etc...
bufferUtf16.toString('latin1')
bufferHex.toString('binary')
bufferHex.toString('latin1')
This string has two characters: \u0012 and '4'.
Buffer.from('\u00124', 'binary')
Loading…

no comments

    sign in to comment