Получение значений от Deno Stdin - PullRequest
0 голосов
/ 20 сентября 2019

Мой вопрос очень короткий, как мы можем получить значения из стандартного ввода?

Я не знаю, как использовать Deno.stdin?

Пример был бы оценен.

Спасибо,

1 Ответ

2 голосов
/ 20 сентября 2019

Deno.stdin имеет тип File, поэтому вы можете прочитать его, указав Uint8Array в качестве буфера и позвонив Deno.stdin.read(buf)

window.onload = async function main() {
  const buf = new Uint8Array(1024);
  /* Reading into `buf` from start.
   * buf.subarray(0, n) is the read result.
   * If n is instead Deno.EOF, then it means that stdin is closed.
   */
  const n = await Deno.stdin.read(buf); 
  if (n == Deno.EOF) {
    console.log("Standard input closed")
  } else {
    console.log("READ:", new TextDecoder().decode(buf.subarray(0, n)));
  }
}
...