JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44
  • Score
    100M100P100Q61632F
  • License MIT

Read a file, or read stdin if no files are specified

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

NPM version Build Status Coverage Status dependencies Status devDependencies Status

Read a file, or read stdin if no files are specified

// echo "Hello!" | node example.js
const fileOrStdin = require('file-or-stdin');

fileOrStdin('path/to/a/file').then(data => {
  data.toString(); // file contents 
});

sfileOrStdin(null).then(data => {
  data.toString(); //=> 'Hello!'
});

Installation

Use npm.

npm install file-or-stdin

API

const fileOrStdout = require('file-or-stdin');

fileOrStdin(filePath [, options])

filePath: String or a falsy value
options: Object (fs.writeFile options) or String (encoding)
Return: Promise

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
fileOrStdin('', 'utf8').then(data => {
  data; //=> 'nodejs'
});
// echo "nodejs" | node example.js
fileOrStdin('', 'base64').then(data => {
  isFileWritten; //=> 'bm9kZWpz'
});

License

Copyright (c) 2016 Shinnosuke Watanabe

Licensed under the MIT License.