2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-24 01:02:12 +01:00
|
|
|
require('../common');
|
2014-04-15 18:44:46 +02:00
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
var Transform = require('stream').Transform;
|
|
|
|
|
|
|
|
var parser = new Transform({ readableObjectMode : true });
|
|
|
|
|
|
|
|
assert(parser._readableState.objectMode);
|
|
|
|
assert(!parser._writableState.objectMode);
|
2014-07-09 00:06:40 +02:00
|
|
|
assert(parser._readableState.highWaterMark === 16);
|
|
|
|
assert(parser._writableState.highWaterMark === (16 * 1024));
|
2014-04-15 18:44:46 +02:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
parser._transform = function(chunk, enc, callback) {
|
2014-04-15 18:44:46 +02:00
|
|
|
callback(null, { val : chunk[0] });
|
|
|
|
};
|
|
|
|
|
|
|
|
var parsed;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
parser.on('data', function(obj) {
|
2014-04-15 18:44:46 +02:00
|
|
|
parsed = obj;
|
|
|
|
});
|
|
|
|
|
|
|
|
parser.end(new Buffer([42]));
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('exit', function() {
|
2014-04-15 18:44:46 +02:00
|
|
|
assert(parsed.val === 42);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var serializer = new Transform({ writableObjectMode : true });
|
|
|
|
|
|
|
|
assert(!serializer._readableState.objectMode);
|
|
|
|
assert(serializer._writableState.objectMode);
|
2014-07-09 00:06:40 +02:00
|
|
|
assert(serializer._readableState.highWaterMark === (16 * 1024));
|
|
|
|
assert(serializer._writableState.highWaterMark === 16);
|
2014-04-15 18:44:46 +02:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
serializer._transform = function(obj, _, callback) {
|
2014-04-15 18:44:46 +02:00
|
|
|
callback(null, new Buffer([obj.val]));
|
2014-07-09 00:06:40 +02:00
|
|
|
};
|
2014-04-15 18:44:46 +02:00
|
|
|
|
|
|
|
var serialized;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
serializer.on('data', function(chunk) {
|
2014-04-15 18:44:46 +02:00
|
|
|
serialized = chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
serializer.write({ val : 42 });
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('exit', function() {
|
2014-04-15 18:44:46 +02:00
|
|
|
assert(serialized[0] === 42);
|
|
|
|
});
|