Skip to content

Commit

Permalink
refactor(cmd/rcat): switch to node:process/stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
sntran committed Jul 7, 2024
1 parent 64b4c10 commit e10099e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/rcat/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from "node:process";
import { fetch } from "../../mod.js";

/**
Expand All @@ -7,9 +8,19 @@ import { fetch } from "../../mod.js";
* @returns {Promise<Response>}
*/
export function rcat(destination, flags) {
const body = new ReadableStream({
start(controller) {
process.stdin.on("data", (chunk) => {
controller.enqueue(chunk);
});
process.stdin.on("end", () => {
controller.close();
});
},
});

return fetch(`${destination}?${new URLSearchParams(flags)}`, {
method: "PUT",
// TODO: Switch to `node:process.stdin`.
body: Deno.stdin.readable,
body,
});
}

0 comments on commit e10099e

Please sign in to comment.