Last active
September 1, 2018 19:58
-
-
Save watson/8f9ce58b77ea4fa193c56f48474bb9b5 to your computer and use it in GitHub Desktop.
Testing write on corked stream in combination with destroy for readable-stream@3
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
'use strict' | |
const { Writable } = require('readable-stream') | |
let stream | |
console.log('write') | |
stream = getStream() | |
stream.write('foo') | |
console.log('write + destroy') | |
stream = getStream() | |
stream.write('foo') | |
stream.destroy() | |
console.log('cork + write + uncork') | |
stream = getStream() | |
stream.cork() | |
stream.write('foo') | |
stream.uncork() | |
console.log('cork + write + uncork + destroy') | |
stream = getStream() | |
stream.cork() | |
stream.write('foo') | |
stream.uncork() | |
stream.destroy() | |
console.log('cork + write + destroy + uncork') | |
stream = getStream() | |
stream.cork() | |
stream.write('foo') | |
stream.destroy() | |
stream.uncork() | |
function getStream () { | |
if (!getStream.n) getStream.n = 0 | |
const n = ++getStream.n | |
const stream = new Writable({ | |
write (chunk, enc, cb) { | |
console.log(` ${n}: write:`, chunk.toString()) | |
cb() | |
} | |
}) | |
stream.on('error', err => { | |
console.log(` ${n}: error event:`, err.message) | |
}) | |
return stream | |
} |
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
write | |
1: write: foo | |
write + destroy | |
2: write: foo | |
cork + write + uncork | |
3: write: foo | |
cork + write + uncork + destroy | |
4: write: foo | |
cork + write + destroy + uncork | |
5: error event: Cannot call write after a stream was destroyed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment