Skip to content

Commit

Permalink
Use streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Sep 22, 2024
1 parent 4e07bbd commit 39be81b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions scripts/actions/upload-to-r2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { Readable } from "node:stream"
import fs from "fs";
import path from "path";

Expand Down Expand Up @@ -51,11 +52,11 @@ async function uploadStableArtifacts({ github, context }) {
// download all the artifacts from the build
for (const artifact of artifacts) {
console.log(`[${tag}] Downloading stable artifact ${artifact.name}`);
fetch(artifact.browser_download_url)
.then(res => res.arrayBuffer())
.then(data => {
fs.writeFileSync(path.join(releaseBinDir, `${artifact.name}`), Buffer.from(data));
});
const response = await fetch(artifact.browser_download_url)
const stream = Readable.fromWeb(response.body)

console.log(`[${tag}] Writing stable artifact ${artifact.name}`);
await fs.promises.writeFile(path.join(releaseBinDir, `${artifact.name}`), stream);
}

try {
Expand Down

0 comments on commit 39be81b

Please sign in to comment.