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
|
|
|
|
2018-02-16 15:46:48 +01:00
|
|
|
const { strictEqual } = require('assert');
|
|
|
|
const { Writable } = require('stream');
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
const w = new Writable();
|
|
|
|
|
|
|
|
w.on('error', common.expectsError({
|
|
|
|
type: Error,
|
|
|
|
code: 'ERR_METHOD_NOT_IMPLEMENTED',
|
|
|
|
message: 'The _write() method is not implemented'
|
|
|
|
}));
|
|
|
|
|
|
|
|
w.end(Buffer.from('blerg'));
|
|
|
|
|
2018-02-16 15:46:48 +01:00
|
|
|
const _write = common.mustCall((chunk, _, next) => {
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
const _writev = common.mustCall((chunks, next) => {
|
|
|
|
strictEqual(chunks.length, 2);
|
|
|
|
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
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
strictEqual(w2._write, _write);
|
|
|
|
strictEqual(w2._writev, _writev);
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
w2.write(Buffer.from('blerg'));
|
2015-02-03 01:12:41 +00:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
w2.cork();
|
|
|
|
w2.write(Buffer.from('blerg'));
|
|
|
|
w2.write(Buffer.from('blerg'));
|
2018-02-06 21:29:26 +01:00
|
|
|
|
2018-02-16 12:53:34 +01:00
|
|
|
w2.end();
|