Skip to content

Instantly share code, notes, and snippets.

@tytrdev
Created December 26, 2019 02:15
Show Gist options
  • Save tytrdev/704f4ae279ee4495b21858eee82686d6 to your computer and use it in GitHub Desktop.
Save tytrdev/704f4ae279ee4495b21858eee82686d6 to your computer and use it in GitHub Desktop.
const { Duplex } = require('stream');
class MyDuplexStream extends Duplex {
constructor(bytes) {
this.buffer = Buffer.alloc(bytes, '', 'utf-8');
this.bytesRead = 0;
}
_read(n) {
this.bytesRead += n;
return this.buffer.toString('utf-8', this.bytesRead - n, this.bytesRead);
}
_write(chunk) {
this.buffer.write(chunk);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment