-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f239454
commit 509ae40
Showing
15 changed files
with
433 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Flags: --expose_internals | ||
/*<replacement>*/ | ||
var bufferShim = require('buffer-shims'); | ||
/*</replacement>*/ | ||
require('../common'); | ||
var assert = require('assert/'); | ||
var BufferList = require('../../lib/internal/streams/BufferList'); | ||
|
||
// Test empty buffer list. | ||
var emptyList = new BufferList(); | ||
|
||
emptyList.shift(); | ||
assert.deepStrictEqual(emptyList, new BufferList()); | ||
|
||
assert.strictEqual(emptyList.join(','), ''); | ||
|
||
assert.deepStrictEqual(emptyList.concat(0), bufferShim.alloc(0)); | ||
|
||
// Test buffer list with one element. | ||
var list = new BufferList(); | ||
list.push('foo'); | ||
|
||
assert.strictEqual(list.concat(1), 'foo'); | ||
|
||
assert.strictEqual(list.join(','), 'foo'); | ||
|
||
var shifted = list.shift(); | ||
assert.strictEqual(shifted, 'foo'); | ||
assert.deepStrictEqual(list, new BufferList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*<replacement>*/ | ||
var bufferShim = require('buffer-shims'); | ||
/*</replacement>*/ | ||
var common = require('../common'); | ||
var assert = require('assert/'); | ||
var Readable = require('../../').Readable; | ||
|
||
var readable = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
// Initialized to false. | ||
assert.strictEqual(readable._readableState.emittedReadable, false); | ||
|
||
readable.on('readable', common.mustCall(function () { | ||
// emittedReadable should be true when the readable event is emitted | ||
assert.strictEqual(readable._readableState.emittedReadable, true); | ||
readable.read(); | ||
// emittedReadable is reset to false during read() | ||
assert.strictEqual(readable._readableState.emittedReadable, false); | ||
}, 4)); | ||
|
||
// When the first readable listener is just attached, | ||
// emittedReadable should be false | ||
assert.strictEqual(readable._readableState.emittedReadable, false); | ||
|
||
// Each one of these should trigger a readable event. | ||
process.nextTick(common.mustCall(function () { | ||
readable.push('foo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
readable.push('bar'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
readable.push('quo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
readable.push(null); | ||
})); | ||
|
||
var noRead = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
noRead.on('readable', common.mustCall(function () { | ||
// emittedReadable should be true when the readable event is emitted | ||
assert.strictEqual(noRead._readableState.emittedReadable, true); | ||
noRead.read(0); | ||
// emittedReadable is not reset during read(0) | ||
assert.strictEqual(noRead._readableState.emittedReadable, true); | ||
})); | ||
|
||
noRead.push('foo'); | ||
noRead.push(null); | ||
|
||
var flowing = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
flowing.on('data', common.mustCall(function () { | ||
// When in flowing mode, emittedReadable is always false. | ||
assert.strictEqual(flowing._readableState.emittedReadable, false); | ||
flowing.read(); | ||
assert.strictEqual(flowing._readableState.emittedReadable, false); | ||
}, 3)); | ||
|
||
flowing.push('foooo'); | ||
flowing.push('bar'); | ||
flowing.push('quo'); | ||
process.nextTick(common.mustCall(function () { | ||
flowing.push(null); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*<replacement>*/ | ||
var bufferShim = require('buffer-shims'); | ||
/*</replacement>*/ | ||
var common = require('../common'); | ||
var assert = require('assert/'); | ||
var Readable = require('../../').Readable; | ||
|
||
var readable = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
// Initialized to false. | ||
assert.strictEqual(readable._readableState.needReadable, false); | ||
|
||
readable.on('readable', common.mustCall(function () { | ||
// When the readable event fires, needReadable is reset. | ||
assert.strictEqual(readable._readableState.needReadable, false); | ||
readable.read(); | ||
})); | ||
|
||
// If a readable listener is attached, then a readable event is needed. | ||
assert.strictEqual(readable._readableState.needReadable, true); | ||
|
||
readable.push('foo'); | ||
readable.push(null); | ||
|
||
readable.on('end', common.mustCall(function () { | ||
// No need to emit readable anymore when the stream ends. | ||
assert.strictEqual(readable._readableState.needReadable, false); | ||
})); | ||
|
||
var asyncReadable = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
asyncReadable.on('readable', common.mustCall(function () { | ||
if (asyncReadable.read() !== null) { | ||
// After each read(), the buffer is empty. | ||
// If the stream doesn't end now, | ||
// then we need to notify the reader on future changes. | ||
assert.strictEqual(asyncReadable._readableState.needReadable, true); | ||
} | ||
}, 3)); | ||
|
||
process.nextTick(common.mustCall(function () { | ||
asyncReadable.push('foooo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
asyncReadable.push('bar'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
asyncReadable.push(null); | ||
})); | ||
|
||
var flowing = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
// Notice this must be above the on('data') call. | ||
flowing.push('foooo'); | ||
flowing.push('bar'); | ||
flowing.push('quo'); | ||
process.nextTick(common.mustCall(function () { | ||
flowing.push(null); | ||
})); | ||
|
||
// When the buffer already has enough data, and the stream is | ||
// in flowing mode, there is no need for the readable event. | ||
flowing.on('data', common.mustCall(function (data) { | ||
assert.strictEqual(flowing._readableState.needReadable, false); | ||
}, 3)); | ||
|
||
var slowProducer = new Readable({ | ||
read: function () {} | ||
}); | ||
|
||
slowProducer.on('readable', common.mustCall(function () { | ||
if (slowProducer.read(8) === null) { | ||
// The buffer doesn't have enough data, and the stream is not ened, | ||
// we need to notify the reader when data arrives. | ||
assert.strictEqual(slowProducer._readableState.needReadable, true); | ||
} else { | ||
assert.strictEqual(slowProducer._readableState.needReadable, false); | ||
} | ||
}, 4)); | ||
|
||
process.nextTick(common.mustCall(function () { | ||
slowProducer.push('foo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
slowProducer.push('foo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
slowProducer.push('foo'); | ||
})); | ||
process.nextTick(common.mustCall(function () { | ||
slowProducer.push(null); | ||
})); |
Oops, something went wrong.