Package Exports
- file-or-stdin
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (file-or-stdin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
file-or-stdin
Read a file, or read stdin if no files are specified
// echo "Hello!" | node example.js
const fileOrStdin = require('file-or-stdin');
(async () => {
(await fileOrStdin('path/to/a/file')).toString() // file contents;
(await fileOrStdin(null)).toString(); //=> 'Hello!'
})();
Installation
npm install file-or-stdin
API
const fileOrStdin = require('file-or-stdin');
fileOrStdin(filePath [, options])
filePath: string
or a falsy value
options: Object
(fs.readFile
options) or string
(encoding)
Return: Promise<Buffer>
or Promise<string>
When the first argument is a file path, it reads the given file and returns a promise of the file contents.
When the first argument is a falsy value, it reads stdin and returns a promise of the buffered stdin data.
// echo "nodejs" | node example.js
(async () => {
await fileOrStdin('', 'utf8'); //=> 'nodejs'
})();
// echo "nodejs" | node example.js
(async () => {
await fileOrStdin('', 'base64'); //=> 'bm9kZWpz'
})();
License
ISC License © 2018 Shinnosuke Watanabe