Skip to content

Instantly share code, notes, and snippets.

@azu
Created May 26, 2015 01:58
Show Gist options
  • Save azu/aed39e9917e3085439a2 to your computer and use it in GitHub Desktop.
Save azu/aed39e9917e3085439a2 to your computer and use it in GitHub Desktop.
コマンドラインで標準入力とファイル名指定をするパターン
#!/usr/bin/env node
var doSome = require('../').doSome;
var concat = require('concat-stream');
var fs = require('fs');
var file = process.argv[2];
var input = file && file !== '-'
? fs.createReadStream(process.argv[2])
: process.stdin
;
input.pipe(concat(function (buf) {
console.log(doSome(buf.toString('utf8')));
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment