Skip to content

Node v4 compatibility

Alexander Shtuchkin edited this page Sep 26, 2015 · 3 revisions

TL;DR extendNodeEncodings() doesn't work in Node v4+. You'll need to update your code to use encode and decode functions directly.

Context

In Node v4, Buffer inherits directly from Uint8Array and all string conversion routines are hidden in local scopes, so it's not possible to use patching machinery of extendNodeEncodings function. It was arguably a hack from the very beginning, so we cannot blame Node authors for it. I'll work with Node community to create an officially supported way of extending encoding set.

Conversion table

NOTE: Streaming API works without changes.

Current (deprecated, bad) Supported equivalent
iconv.extendNodeEncodings() --
iconv.undoExtendNodeEncodings() --
new Buffer(str, enc) iconv.encode(str, enc)
buf.toString(enc) iconv.decode(buf, enc)
buf.write(str, enc) iconv.encode(str, enc).copy(buf)
Buffer.isEncoding(enc) iconv.encodingExists(enc)
stream.setEncoding(enc) stream = stream.pipe(iconv.decodeStream(enc))
fs.createReadStream(file, enc) fs.createReadStream(file).pipe(iconv.decodeStream(enc))
Clone this wiki locally