-
Notifications
You must be signed in to change notification settings - Fork 282
Node v4 compatibility
Alexander Shtuchkin edited this page Sep 26, 2015
·
3 revisions
TL;DR: extendNodeEncodings()
doesn't work with Node v4+. You'll need to update your code to use encode
and decode
functions directly.
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. We'll work with Node community to create an officially supported way of extending encoding set.
Utf8 will be used instead. This is the default behavior when you give an unknown encoding to Node.
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)) |
Issues: #105, nodejs/node#2835