Created
December 26, 2019 02:15
-
-
Save tytrdev/704f4ae279ee4495b21858eee82686d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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