| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | |
| 2 | var _Readable = require('readable-stream/readable'); |
| 3 | var _Writable = require('readable-stream/writable'); |
| 4 | var util = require('util'); |
| 5 | |
| 6 | module.exports = { |
| 7 | DummyReadable: DummyReadable, |
| 8 | DummyWritable: DummyWritable |
| 9 | }; |
| 10 | |
| 11 | function DummyReadable(strings) { |
| 12 | _Readable.call(this); |
| 13 | this.strings = strings; |
| 14 | this.emit('readable'); |
| 15 | } |
| 16 | |
| 17 | util.inherits(DummyReadable, _Readable); |
| 18 | |
| 19 | DummyReadable.prototype._read = function _read(n) { |
| 20 | if (this.strings.length) { |
| 21 | this.push(new Buffer(this.strings.shift())); |
| 22 | } else { |
| 23 | this.push(null); |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | function DummyWritable(strings) { |
| 28 | _Writable.call(this); |
| 29 | this.strings = strings; |
| 30 | this.emit('writable'); |
| 31 | } |
| 32 | |
| 33 | util.inherits(DummyWritable, _Writable); |
| 34 | |
| 35 | DummyWritable.prototype._write = function _write(chunk, encoding, callback) { |
| 36 | this.strings.push(chunk.toString()); |
| 37 | if (callback) callback(); |
| 38 | }; |
| 39 | |