Skip to content

Commit bc3ce2b

Browse files
authored
Simplify reading of .json.gz using web technologies only (#3105)
1 parent 087dc9e commit bc3ce2b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

scripts/audit-consumers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import zlib from "node:zlib";
2-
import stream from "node:stream/promises";
3-
41
import * as cheerio from "cheerio";
52
import { Octokit } from "@octokit/rest";
63

@@ -12,6 +9,12 @@ interface Report {
129
trailer: string;
1310
}
1411

12+
// Parse the contents of a stream as JSON. Inspired by Bun docs:
13+
// https://bun.sh/guides/streams/node-readable-to-json
14+
function json(stream: ReadableStream): Promise<any> {
15+
return new Response(stream).json();
16+
}
17+
1518
// Yield all entries from chromestatus.com. Because the newest entry is returned
1619
// first and entries might be created while we're iterating, it's possible that
1720
// the same entry is yielded multiple times. If this is a problem they have to be
@@ -155,13 +158,10 @@ async function wptReport(): Promise<Report> {
155158
throw new Error(`Failed to download ${asset.browser_download_url}`);
156159
}
157160

158-
const gunzip = zlib.createGunzip();
159-
const chunks = [];
160-
gunzip.on("data", (chunk) => chunks.push(chunk));
161-
await stream.pipeline(response.body, gunzip);
162-
const json = Buffer.concat(chunks).toString("utf-8");
161+
const manifest = await json(
162+
response.body.pipeThrough(new DecompressionStream("gzip")),
163+
);
163164

164-
const manifest = JSON.parse(json);
165165
const ids = Object.keys(manifest.data);
166166

167167
const items = [];

0 commit comments

Comments
 (0)