6

I'm trying to figure out what encodings are available in node.js.

The documentation (http://nodejs.org/api/buffer.html#buffer_new_buffer_str_encoding) says:

Allocates a new buffer containing the given str. encoding defaults to 'utf8'.

but nowhere is specified a list of available encodings. Maybe I missed it.

I'm working on script which should be able to output in wide range of encodings. So far I know only about utf8 as doc is saying :)

Thx, Jaro.

2
  • 2
    Check out iconv-lite if you need more encodings than supported natively by Node. Commented Nov 26, 2013 at 18:19
  • Have to admit, I came here in exactly the same circumstance. The nodejs documentation is still poorly structured and not including any links/references to supported encodings for read and write operations is bad. Commented Jul 29, 2015 at 10:21

2 Answers 2

7

Encodings available in Node.js:

  • ascii: For 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.
  • utf8: Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
  • utf16le: 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
  • ucs2: Alias of utf16le.
  • base64: Base64 encoding. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC 4648, Section 5.
  • latin1: A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC 1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).
  • binary: Alias for 'latin1'.
  • hex: Encode each byte as two hexadecimal characters.

Source: Node 12 Buffer documentation

Sign up to request clarification or add additional context in comments.

1 Comment

by default buffer does not support iso-8859-1. I googled around and found another thread stackoverflow.com/questions/14551608/… . The solution is based on node-iconv npm. I'll give it a try. Thanks.
0

in order to clarify lastest nodejs encoding explaination. I paste from nodejs document. v4+ does't deprated binary

The character encodings currently supported by Node.js include:

'ascii' - For 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.

'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.

'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.

'ucs2' - Alias of 'utf16le'.

'base64' - Base64 encoding. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC 4648, Section 5.

'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC 1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).

'binary' - Alias for 'latin1'.

'hex' - Encode each byte as two hexadecimal characters.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.