File: index.js

package info (click to toggle)
node-get-stdin 8.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 164 kB
  • sloc: javascript: 136; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 497 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const {stdin} = process;

module.exports = async () => {
	let result = '';

	if (stdin.isTTY) {
		return result;
	}

	stdin.setEncoding('utf8');

	for await (const chunk of stdin) {
		result += chunk;
	}

	return result;
};

module.exports.buffer = async () => {
	const result = [];
	let length = 0;

	if (stdin.isTTY) {
		return Buffer.concat([]);
	}

	for await (const chunk of stdin) {
		result.push(chunk);
		length += chunk.length;
	}

	return Buffer.concat(result, length);
};