Skip to content

Commit

Permalink
fix(wpt): download files as buffer instead of text
Browse files Browse the repository at this point in the history
There are binary files in the WPT repository and downloading them as
text corrupts them.

Refs: nodejs/node#37294
  • Loading branch information
targos committed Feb 21, 2021
1 parent 059c138 commit d97f83c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/github/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit d97f83c

Please sign in to comment.