How can I pipe the contents of a file into a Deno script for processing?
EG:
cat names.txt | deno run deno-script.ts
OR
cat names.txt | deno-script.ts
In node.js we can do the following:
#!/usr/local/bin/node
// The shebang above lets us run the script directly,
// without needing to include `node` before the script name.
const stdin = process.openStdin();
stdin.on('data', chunk => {
const lines = chunk.toString().split('\n');
lines.forEach(line => {
// process each line...
console.log(line);
})
})
Deno's stdin is a bit different, this answer shows how I can use a buffer to use a chunk of stdin into memory and start processing.
What's the best way to read and process the data line by line?