diff --git a/src/manager.ts b/src/manager.ts index f081154..8325dd5 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -13,11 +13,9 @@ import type { Navigation } from './webviewMessages'; async function tryGetHome(ssh: Client): Promise { const exec = await toPromise(cb => ssh.exec('echo Home: ~', cb)); - const { MemoryDuplex } = await import('./streams'); - const stdout = new MemoryDuplex(); - exec.stdout.pipe(stdout); + let home = ''; + exec.stdout.on('data', (chunk: any) => home += chunk); await toPromise(cb => exec.on('close', cb)); - const home = stdout.read().toString(); if (!home) return null; const mat = home.match(/^Home: (.*?)\r?\n?$/); if (!mat) return null; diff --git a/src/streams.ts b/src/streams.ts deleted file mode 100644 index 269be99..0000000 --- a/src/streams.ts +++ /dev/null @@ -1,48 +0,0 @@ - -import { Duplex, Writable } from 'stream'; - -export class MemoryDuplex extends Duplex { - protected buffer = Buffer.alloc(this.size); - protected buffered = 0; - protected doPush = false; - constructor(public readonly size: number = 4092) { - super(); - } - // tslint:disable-next-line:function-name - public _write(chunk: any, encoding: string, callback: (err?: Error) => void) { - const buffer = chunk instanceof Buffer ? chunk : Buffer.from(chunk.toString(), encoding as BufferEncoding); - const end = this.buffered + buffer.length; - if (end > this.size) { - return callback(new Error('Buffer overflow')); - } - this.buffered += buffer.copy(this.buffer, this.buffered, 0); - if (this.doPush) this._read(); - callback(); - } - // tslint:disable-next-line:function-name - public _read() { - const slice = this.buffer.slice(0, this.buffered); - this.buffered = 0; - this.buffer = Buffer.alloc(this.size); - this.doPush = this.push(slice); - } - public bytesBuffered() { - return this.buffered; - } -} - -export class WritableFunctionStream extends Writable { - constructor(protected func: (data: Buffer) => void | Promise) { - super(); - } - // tslint:disable-next-line:function-name - public async _write(chunk: any, encoding: string, callback: (err?: Error) => void) { - const buffer = chunk instanceof Buffer ? chunk : Buffer.from(chunk.toString(), encoding as BufferEncoding); - try { - await this.func(buffer); - callback(); - } catch (e) { - callback(e); - } - } -}