1 | const {stdin} = process;
|
2 |
|
3 | export default async function getStdin() {
|
4 | let result = '';
|
5 |
|
6 | if (stdin.isTTY) {
|
7 | return result;
|
8 | }
|
9 |
|
10 | stdin.setEncoding('utf8');
|
11 |
|
12 | for await (const chunk of stdin) {
|
13 | result += chunk;
|
14 | }
|
15 |
|
16 | return result;
|
17 | }
|
18 |
|
19 | getStdin.buffer = async () => {
|
20 | const result = [];
|
21 | let length = 0;
|
22 |
|
23 | if (stdin.isTTY) {
|
24 | return Buffer.concat([]);
|
25 | }
|
26 |
|
27 | for await (const chunk of stdin) {
|
28 | result.push(chunk);
|
29 | length += chunk.length;
|
30 | }
|
31 |
|
32 | return Buffer.concat(result, length);
|
33 | };
|