summaryrefslogtreecommitdiff
path: root/node_modules/read-file-stdin/index.js
blob: 3b6d88b143f7a44f8b22c227544d6de5af723e24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

var gather = require('gather-stream');
var fs = require('fs');

/**
 * Expose `read`.
 */

module.exports = read;

/**
 * Read from a `file`, falling back to stdin, and `callback(err, buffer)`.
 *
 * @param {String} file
 * @param {Function} callback
 */

function read (file, callback) {
  if ('function' == typeof file) callback = file, file = null;
  var stream = file ? fs.createReadStream(file) : process.stdin;
  stream.pipe(gather(callback));
}