-
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 in Node v4+. You'll need to update your code to useencode
anddecode
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. I'll work with Node community to create an officially supported way of extending encoding set.
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)) |