ptyw.js icon indicating copy to clipboard operation
ptyw.js copied to clipboard

setEncoding() fails if encoding is not Node native

Open NuSkooler opened this issue 10 years ago • 3 comments

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 avatar Nov 20 '15 19:11 NuSkooler

@NuSkooler I created a branch for this, try with https://github.com/iiegor/ptyw.js/tree/fix-set-encoding.

iiegor avatar Nov 21 '15 14:11 iiegor

@iiegor, thanks for the quick response. I tried the fix-set-encoding branch: This prevents the initial crash, but introduces a few new issues:

  1. Garbage output
  2. Keyboard input breaks
  3. 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!

NuSkooler avatar Nov 21 '15 17:11 NuSkooler

BTW, this workaround functions:

door.on('data', function dataIn(data) {
  self.client.term.write(decode(data, 'cp437')); /* or whatever encoding */
});

NuSkooler avatar Dec 13 '15 00:12 NuSkooler