setEncoding() fails if encoding is not Node native
setEncoding() will throw if encoding is not native to Node. In earlier versions of Node.js, one could expand the supported encodings Node supported (e.g. with iconv-lite). This has changed in 4+.
See https://github.com/ashtuchkin/iconv-lite/wiki/Node-v4-compatibility
@NuSkooler I created a branch for this, try with https://github.com/iiegor/ptyw.js/tree/fix-set-encoding.
@iiegor, thanks for the quick response. I tried the fix-set-encoding branch: This prevents the initial crash, but introduces a few new issues:
- Garbage output
- Keyboard input breaks
- Crash when closing:
< events.js:85
< throw er; // Unhandled 'error' event
< ^
< Error: read EIO
< at exports._errnoException (util.js:746:11)
< at Pipe.onread (net.js:559:26)
program terminated
I was able to fix (1) above by changing some code in the ctor:
// this.socket.setEncoding('utf8');
// changed to this:
this.socket = this.socket.pipe(decodeStream(opt.encoding || 'utf8'));
Of course, this doesn't solve (2) or (3) and setEncoding() itself remains broken. If you have any ideas I'd love to try them!
BTW, this workaround functions:
door.on('data', function dataIn(data) {
self.client.term.write(decode(data, 'cp437')); /* or whatever encoding */
});