How to read all text from stdin.
It uses to be simple with the
Deta.readAll
function.
Now it is deprecated, link to https://deno.land/std/streams/read_all.ts?s=readAll (which is also deprecated).
The deprecation message says: Use ReadableStream and toArrayBuffer instead
.
A specific example would be better.
Basically, I want
but working on windows7 Replies
Ok I found it. Here it is for future reference
To read all text from stdin in Deno, you can use the
Deno.stdin
variable which provides a ReadableStream
interface. Here is an example from the documentation:
In this example, Deno.stdin.readable
is a ReadableStream
that you can asynchronously iterate over to get chunks of data from stdin. Each chunk is a Uint8Array
that you can decode into a string using TextDecoder
.
Please note that this code will read from stdin until it encounters an EOF (End of File) marker, which signals that there is no more data to read. In a terminal, you can usually send an EOF marker by pressing Ctrl+D
(on Unix-like systems) or Ctrl+Z
(on Windows).
This method should work across different platforms including Windows. However, please note that the behavior might be slightly different depending on the terminal or command line interface you are using.Since you're already importing from the std, might as well use
toText
instead!
thanks! toJson is also quite useful
👍
wow this looks weird