Skip to content

Commit 711fb48

Browse files
use pipes
1 parent 9e3e092 commit 711fb48

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

packages/@pglt/pglt/scripts/generate-packages.mjs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import assert from "node:assert";
22
import * as fs from "node:fs";
3+
import { pipeline } from "node:stream";
34
import { resolve } from "node:path";
45
import { fileURLToPath } from "node:url";
5-
import { format } from "node:util";
6+
import { format, promisify } from "node:util";
67

78
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
89
const PACKAGES_PGLT_ROOT = resolve(CLI_ROOT, "..");
910
const PGLT_ROOT = resolve(PACKAGES_PGLT_ROOT, "../..");
1011
const MANIFEST_PATH = resolve(CLI_ROOT, "package.json");
1112

13+
const streamPipeline = promisify(pipeline);
14+
1215
async function downloadSchema(releaseTag, githubToken) {
1316
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${releaseTag}/schema.json`;
1417

@@ -26,11 +29,7 @@ async function downloadSchema(releaseTag, githubToken) {
2629
// download to root.
2730
const fileStream = fs.createWriteStream(resolve(PGLT_ROOT, "schema.json"));
2831

29-
await new Promise((res, rej) => {
30-
response.body.pipeTo(fileStream);
31-
fileStream.on("error", rej);
32-
fileStream.on("finish", res);
33-
});
32+
await streamPipeline(response.body, fileStream);
3433

3534
console.log(`Downloaded schema for ${releaseTag}`);
3635
}
@@ -53,11 +52,7 @@ async function downloadAsset(platform, os, arch, releaseTag, githubToken) {
5352
// just download to root.
5453
const fileStream = fs.createWriteStream(getBinarySource(os, platform, arch));
5554

56-
await new Promise((res, rej) => {
57-
response.body.pipeTo(fileStream);
58-
fileStream.on("error", rej);
59-
fileStream.on("finish", res);
60-
});
55+
await streamPipeline(response.body, fileStream);
6156

6257
console.log(`Downloaded asset for ${buildName} (v${releaseTag})`);
6358
}

0 commit comments

Comments
 (0)