2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-02-06 21:29:26 +01:00
|
|
|
const common = require('../common');
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2020-02-22 12:28:26 +01:00
|
|
|
const assert = require('assert');
|
2018-02-16 15:46:48 +01:00
|
|
|
const { Writable } = require('stream');
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2019-06-21 17:39:34 -05:00
|
|
|
const bufferBlerg = Buffer.from('blerg');
|
2020-02-22 12:28:26 +01:00
|
|
|
const w = new Writable();
|
2019-06-21 17:39:34 -05:00
|
|
|
|
2020-02-22 12:28:26 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
|
|
|
w.end(bufferBlerg);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Error',
|
|
|
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
|
|
|
message: 'The _write() method is not implemented'
|
|
|
|
}
|
|
|
|
);
|
2018-02-16 12:53:34 +01:00
|
|
|
|
2018-02-16 15:46:48 +01:00
|
|
|
const _write = common.mustCall((chunk, _, next) => {
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
const _writev = common.mustCall((chunks, next) => {
|
2020-02-22 12:28:26 +01:00
|
|
|
assert.strictEqual(chunks.length, 2);
|
2018-02-16 15:46:48 +01:00
|
|
|
next();
|
|
|
|
});
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
const w2 = new Writable({ write: _write, writev: _writev });
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2020-02-22 12:28:26 +01:00
|
|
|
assert.strictEqual(w2._write, _write);
|
|
|
|
assert.strictEqual(w2._writev, _writev);
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2019-06-21 17:39:34 -05:00
|
|
|
w2.write(bufferBlerg);
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
w2.cork();
|
2019-06-21 17:39:34 -05:00
|
|
|
w2.write(bufferBlerg);
|
|
|
|
w2.write(bufferBlerg);
|
2018-02-06 21:29:26 +01:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
w2.end();
|