Chunk strings together on Stream buffer
This commit is contained in:
parent
c75e4cb48a
commit
301b44d45d
11
lib/net.js
11
lib/net.js
@ -504,8 +504,15 @@ Stream.prototype.write = function (data, encoding) {
|
||||
if (this._writeQueueLast() === END_OF_FILE) {
|
||||
throw new Error('Stream.close() called already; cannot write.');
|
||||
}
|
||||
this._writeQueue.push(data); // TODO if string of the same encoding concat?
|
||||
this._writeQueueEncoding.push(encoding);
|
||||
|
||||
if (typeof data == 'string' &&
|
||||
this._writeQueueEncoding[this._writeQueueEncoding.length-1] === encoding) {
|
||||
// optimization - concat onto last
|
||||
this._writeQueue[this._writeQueue.length-1] += data;
|
||||
} else {
|
||||
this._writeQueue.push(data);
|
||||
this._writeQueueEncoding.push(encoding);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
// Fast.
|
||||
|
@ -12,7 +12,7 @@ var chargen = http.createServer(function (req, res) {
|
||||
assert.ok(len > 0);
|
||||
res.writeHead(200, {"transfer-encoding":"chunked"});
|
||||
for (var i=0; i<len; i++) {
|
||||
//print(',');
|
||||
if (i % 1000 == 0) print(',');
|
||||
res.write(chunk);
|
||||
}
|
||||
res.end();
|
||||
@ -38,8 +38,10 @@ var proxy = http.createServer(function (req, res) {
|
||||
proxy_req.addListener('response', function(proxy_res) {
|
||||
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
||||
|
||||
var count = 0;
|
||||
|
||||
proxy_res.addListener('data', function(d) {
|
||||
//print('.');
|
||||
if (count++ % 1000 == 0) print('.');
|
||||
res.write(d);
|
||||
sent += d.length;
|
||||
assert.ok(sent <= (len*chunk.length));
|
||||
|
Loading…
x
Reference in New Issue
Block a user