Skip to content

Commit

Permalink
documented the helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
williamkapke committed Jul 16, 2013
1 parent 02f1e09 commit 53da4e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -58,6 +58,22 @@ Use with `pipe()` optionally specifying the encoding.
###eachline(ReadableStream,[ encoding,] callback)
Got that stream ready? Pass it in, get them lines. Easy-peasy.

###eachline.in(url, callback)
###eachline.in(filepath, callback)
Just a helper function to make these simple tasks cleaner.

It returns the `Transform` stream so you can listen to the events.
```javascript
var linecount = 0;
var eachline = require('eachline');
eachline.in(__dirname+'/.gitignore', function(line){
linecount++;
})
.on('finish', function(){
console.log(linecount + " lines found");
});
```

**callback(line)**<BR>
The `callback` arguments above will be called for every line found in the `ReadableStream`.

Expand Down
10 changes: 8 additions & 2 deletions eachline.js
Expand Up @@ -66,17 +66,23 @@ module.exports.in = function(location, cb){
var args = Array.prototype.slice.call(arguments);
var web = /(https?):\/\//.exec(location);
if(web){
var ev = new (require('events').EventEmitter)();
location = require('url').parse(location);
location.agent = false;
require(web[1]).get(location, function(res){
args[0] = res;
eachline.apply(this, args);
var t = eachline.apply(this, args);
Object.keys(ev._events).forEach(function(event){
t._events[event] = ev._events[event];
});
console.log(Object.keys(ev._events), Object.keys(t._events));
})
.end();
return ev;
}
else {
args[0] = require('fs').createReadStream(location);
eachline.apply(this, args);
return eachline.apply(this, args);
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "eachline",
"version": "1.0.0",
"version": "1.0.1",
"description": "Streams2 line reader",
"keywords": [
"streams2",
Expand All @@ -11,11 +11,11 @@
"type": "git",
"url": "git://github.com/williamwicks/node-eachline.git"
},
"author": "William Wicks <wjwicks@gmail.com>",
"author": "William Wicks<wjwicks@gmail.com>",
"main": "./eachline.js",
"dependencies": {
},
"engines": {
"node": ">= 0.10.0"
"node": ">=0.10.0"
}
}

0 comments on commit 53da4e4

Please sign in to comment.