Fix escape/de-escaping for zmodem & friends

This commit is contained in:
Bryan Ashby 2018-07-16 22:43:19 -06:00
parent e3c197c3e1
commit 1f396e198e
1 changed files with 15 additions and 5 deletions

View File

@ -52,9 +52,12 @@ exports.getModule = class ArchaicNETModule extends MenuModule {
let pipeRestored = false;
let pipedStream;
const restorePipe = function() {
if(pipedStream && !pipeRestored && !clientTerminated) {
self.client.term.output.unpipe(pipedStream);
self.client.term.output.resume();
if(!pipeRestored) {
if(pipedStream && !clientTerminated) {
self.client.term.output.unpipe(pipedStream);
self.client.term.output.resume();
}
self.client.restoreDataHandler();
}
};
@ -82,8 +85,15 @@ exports.getModule = class ArchaicNETModule extends MenuModule {
pipedStream = stream;
self.client.term.output.pipe(stream);
stream.on('data', d => {
return self.client.term.rawWrite(d);
// we need to filter I/O for escape/de-escaping zmodem and the like
self.client.setTemporaryDirectDataHandler(data => {
const tmp = data.toString('binary').replace(/\xff{2}/g, '\xff'); // de-escape
stream.write(Buffer.from(tmp, 'binary'));
});
stream.on('data', data => {
const tmp = data.toString('binary').replace(/\xff/g, '\xff\xff'); // escape
self.client.term.rawWrite(Buffer.from(tmp, 'binary'));
});
stream.on('close', () => {