mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
11 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
|
||
|
var Transform = require('stream').Transform;
|
||
|
|
||
|
var parser = new Transform({ readableObjectMode : true });
|
||
|
|
||
|
assert(parser._readableState.objectMode);
|
||
|
assert(!parser._writableState.objectMode);
|
||
11 years ago
|
assert(parser._readableState.highWaterMark === 16);
|
||
|
assert(parser._writableState.highWaterMark === (16 * 1024));
|
||
11 years ago
|
|
||
|
parser._transform = function (chunk, enc, callback) {
|
||
|
callback(null, { val : chunk[0] });
|
||
|
};
|
||
|
|
||
|
var parsed;
|
||
|
|
||
|
parser.on('data', function (obj) {
|
||
|
parsed = obj;
|
||
|
});
|
||
|
|
||
|
parser.end(new Buffer([42]));
|
||
|
|
||
|
process.on('exit', function () {
|
||
|
assert(parsed.val === 42);
|
||
|
});
|
||
|
|
||
|
|
||
|
var serializer = new Transform({ writableObjectMode : true });
|
||
|
|
||
|
assert(!serializer._readableState.objectMode);
|
||
|
assert(serializer._writableState.objectMode);
|
||
11 years ago
|
assert(serializer._readableState.highWaterMark === (16 * 1024));
|
||
|
assert(serializer._writableState.highWaterMark === 16);
|
||
11 years ago
|
|
||
|
serializer._transform = function (obj, _, callback) {
|
||
|
callback(null, new Buffer([obj.val]));
|
||
11 years ago
|
};
|
||
11 years ago
|
|
||
|
var serialized;
|
||
|
|
||
|
serializer.on('data', function (chunk) {
|
||
|
serialized = chunk;
|
||
|
});
|
||
|
|
||
|
serializer.write({ val : 42 });
|
||
|
|
||
|
process.on('exit', function () {
|
||
|
assert(serialized[0] === 42);
|
||
|
});
|