getStdin.js 285 B

123456789101112131415
  1. 'use strict';
  2. /**
  3. * @param {NodeJS.ReadStream} [stdin]
  4. * @returns {Promise<string>}
  5. */
  6. module.exports = async function getStdin(stdin = process.stdin) {
  7. const chunks = [];
  8. for await (const chunk of stdin) {
  9. chunks.push(chunk);
  10. }
  11. return Buffer.concat(chunks).toString();
  12. };