Skip to content

Commit

Permalink
Add readFileStream example
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanfeust committed Aug 16, 2015
1 parent e12df4e commit cd814a3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var dir = require('node-dir');
```

#### readFiles( dir, [options], fileCallback, [finishedCallback] )
#### readFilesStream( dir, [options], streamCallback, [finishedCallback] )
Sequentially read the content of each file in a directory, passing the contents to a callback, optionally calling a finished callback when complete. The options and finishedCallback arguments are not required.

Valid options are:
Expand Down Expand Up @@ -46,6 +47,24 @@ dir.readFiles(__dirname,
console.log('finished reading files:', files);
});

// display contents of huge files in this script's directory
dir.readFilesStream(__dirname,
function(err, stream, next) {
if (err) throw err;
var content = '';
stream.on('data',function(buffer) {
content += buffer.toString();
});
stream.on('end',function() {
console.log('content:', content);
next();
});
},
function(err, files){
if (err) throw err;
console.log('finished reading files:', files);
});

// match only filenames with a .txt extension and that don't start with a `.´
dir.readFiles(__dirname, {
match: /.txt$/,
Expand Down

0 comments on commit cd814a3

Please sign in to comment.