Skip to content

Commit 9379650

Browse files
committed
merge :: 'devel' of github.com:mimetnet/node-stream-array
* 'devel' of github.com:mimetnet/node-stream-array: test/3.js :: verify that `NaN` throws an error as a source object README.md :: unnecessary cleanup README.md :: clearly state that the source array is not modified .travis.yml :: use only tape and not covert for node v0.10 test/4.js :: use trick to make it look like we're covering a test line test/4.js :: added test to verify that source arrays are not modified test/0.js :: removed test as fastqueue is no longer used package.json :: remove fastqueue as it is no longer used index.js :: fix issue #2 by not modifying the source array
2 parents 05eed0b + fac3c8c commit 9379650

File tree

7 files changed

+50
-51
lines changed

7 files changed

+50
-51
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
language: node_js
2+
23
before_install:
34
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28'
45
- npm install -g npm@latest
5-
- '[ "${TRAVIS_NODE_VERSION}" == "0.8" ] || npm install -g covert'
6+
- '[ "${TRAVIS_NODE_VERSION}" == "0.8" -o "${TRAVIS_NODE_VERSION}" == "0.10" ] || npm install -g covert'
7+
68
script:
7-
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm test'
8-
- '[ "${TRAVIS_NODE_VERSION}" == "0.8" ] || npm run coverage'
9+
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" -a "${TRAVIS_NODE_VERSION}" != "0.10" ] || npm test'
10+
- '[ "${TRAVIS_NODE_VERSION}" == "0.8" -o "${TRAVIS_NODE_VERSION}" == "0.10" ] || npm run coverage'
11+
912
node_js:
1013
- '0.8'
1114
- '0.10'

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# stream-array
22

3-
Pipe an Array through Node.js streams. This is rather useful for testing other
4-
streams.
3+
Pipe an Array through Node.js [Streams][12]. This is rather useful for testing
4+
other streams.
55

6-
[![npm version][1]][2] [![build status][3]][4] [![dependencies][5]][6] [![devDependencies][7]][8]
6+
[![npm version][1]][2]
7+
[![build status][3]][4]
8+
[![dependencies][5]][6]
9+
[![devDependencies][7]][8]
710

811
[//]: [![testling][9]][10]
912

@@ -21,19 +24,23 @@ streamify(['1', '2', '3', os.EOL]).pipe(process.stdout);
2124
## API
2225

2326
#### streamify(Array)
24-
The result of [require][13] is a 'function' that when invoked, will return a [Readable][11] [Stream][12].
27+
The result of [require][13] is a 'function()' that when invoked, will return a
28+
[Readable][11] [Stream][12].
2529

2630
```
2731
var streamify = require('stream-array');
2832
```
2933

30-
The Array passed into stream-array() can contain any type, as it assumes the receiving stream can handle it. Each element will be dequeued and pushed into the following piped stream.
34+
The source array can contain any type as it is assumed that the receiving
35+
stream can handle it. Each element in the array will be [pushed][14] into the
36+
[piped][15] stream, **without** modifying the source array.
3137

3238
```
3339
var readable = streamify(['Hello', new Buffer('World')]);
3440
```
3541

36-
This [Stream][12] will emit each element of the source array as chunks.
42+
This [Stream][12] will [push][14] each element of the source array into the
43+
[piped][15] array.
3744

3845
```
3946
readable(['1', '2', '3', os.EOL]).pipe(process.stdout);
@@ -45,7 +52,7 @@ readable(['1', '2', '3', os.EOL]).pipe(process.stdout);
4552

4653
## Install
4754

48-
```
55+
```sh
4956
npm install stream-array
5057
```
5158

@@ -62,6 +69,8 @@ npm install stream-array
6269
[11]: http://nodejs.org/api/stream.html#stream_class_stream_readable
6370
[12]: http://nodejs.org/api/stream.html#stream_stream
6471
[13]: http://nodejs.org/api/globals.html#globals_require
72+
[14]: https://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding
73+
[15]: https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
6574

6675
## License
6776

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var Readable = require('readable-stream').Readable
2-
, Queue = require('fastqueue')
32
;
43

54
function StreamArray(list) {
@@ -8,15 +7,15 @@ function StreamArray(list) {
87

98
Readable.call(this, {objectMode:true});
109

11-
this._queue = new Queue();
12-
this._queue.tail = list;
13-
this._queue.length = list.length;
10+
this._i = 0;
11+
this._l = list.length;
12+
this._list = list;
1413
}
1514

1615
StreamArray.prototype = Object.create(Readable.prototype, {constructor: {value: StreamArray}});
1716

1817
StreamArray.prototype._read = function(size) {
19-
this.push(this._queue.length ? this._queue.shift() : null);
18+
this.push(this._i < this._l ? this._list[this._i++] : null);
2019
};
2120

2221
module.exports = function(list) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"version": "1.0.2",
44
"description": "Pipe an Array through Node.js streams",
55
"dependencies": {
6-
"readable-stream": "~1.1.0",
7-
"fastqueue": "~0.1.0"
6+
"readable-stream": "~1.1.0"
87
},
98
"devDependencies": {
109
"concat-stream": "~1.4.8",

test/0.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

test/3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test('ctor', function(t) {
77
streamify();
88
}, 'throws: no argument');
99

10-
[null, undefined, 1, 'string', new Object(), function(){}].forEach(
10+
[null, undefined, 1, NaN, 'string', new Object(), function(){}].forEach(
1111
function(item) {
1212
t.throws(function() {
1313
streamify(item);

test/4.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var test = require('tape')
2+
, streamify = require('..')
3+
, concat = require('concat-stream')
4+
;
5+
6+
test('immutable', function(t) {
7+
var s, a = [1, 2, 3, 4, 5];
8+
9+
if (Object && 'function' === typeof(Object.observe)) {
10+
// will produce ugly error, but also doesn't
11+
// cause `covert` to detect an untested line
12+
Object.observe(a, t.fail);
13+
}
14+
15+
s = streamify(a);
16+
17+
s.pipe(concat({encoding: 'object'}, function(res) {
18+
t.equal(1, arguments.length, 'concat returns 1 arg');
19+
t.deepEqual(a, res, 'result array matches input');
20+
t.end();
21+
}));
22+
});

0 commit comments

Comments
 (0)