From 37647da5e9b1614f4fee028e1e3ad495f1e0ca27 Mon Sep 17 00:00:00 2001 From: Rena Wolford Date: Mon, 22 Feb 2021 16:09:31 +0100 Subject: [PATCH] fix(wpt): download files as buffer instead of text (#535) There are binary files in the WPT repository and downloading them as text corrupts them. Refs: https://github.com/nodejs/node/pull/37294 --- lib/github/tree.js | 4 ++-- lib/request.js | 4 ++++ lib/wpt/index.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/github/tree.js b/lib/github/tree.js index 79b5819..a64bb22 100644 --- a/lib/github/tree.js +++ b/lib/github/tree.js @@ -58,10 +58,10 @@ class GitHubTree { return `${this.repoUrl}/tree/${commit.slice(0, 10)}/${this.path}`; } - async text(assetPath) { + async buffer(assetPath) { await this.getLastCommit(); const url = this.getAssetUrl(assetPath); - return this.request.text(url); + return this.request.buffer(url); } /** diff --git a/lib/request.js b/lib/request.js index e33b908..8ba878b 100644 --- a/lib/request.js +++ b/lib/request.js @@ -37,6 +37,10 @@ class Request { return wrappedFetch(url, options); } + async buffer(url, options = {}) { + return this.fetch(url, options).then(res => res.buffer()); + } + async text(url, options = {}) { return this.fetch(url, options).then(res => res.text()); } diff --git a/lib/wpt/index.js b/lib/wpt/index.js index fec5531..3085bab 100644 --- a/lib/wpt/index.js +++ b/lib/wpt/index.js @@ -49,7 +49,7 @@ class WPTUpdater { // If filepath starts with '/', the path is relative to WPT project root, // otherwise it's relative to the path of this updater async pullTextFile(dest, filepath) { - const content = await this.tree.text(filepath); + const content = await this.tree.buffer(filepath); const filename = path.join(dest, filepath); writeFile(filename, content); this.cli.updateSpinner(`Downloaded ${filename}`);