Skip to content

Commit

Permalink
feat: use Buffer.concat
Browse files Browse the repository at this point in the history
  • Loading branch information
elrrrrrrr committed Jul 9, 2023
1 parent 456e684 commit 0728b94
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions app/common/PackageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ export async function extractPackageJSON(tarballBytes: Buffer): Promise<PackageJ
Readable.from(tarballBytes)
.pipe(tar.t({
filter: name => name === 'package/package.json',
onentry: entry => {
let json = '';
entry.on('data', data => {
json += data.toString();
});
entry.on('end', () => {
try {
resolve(JSON.parse(json));
} catch (err) {
reject(new Error('Error parsing package.json'));
}
});
onentry: async entry => {
let chunks: Buffer[] = [];
for await (let chunk of entry) {
chunks.push(chunk);
}
try {
const data = Buffer.concat(chunks);
return resolve(JSON.parse(data.toString()));
} catch (err) {
reject(new Error('Error parsing package.json'));
}
},
}));
});
Expand Down

0 comments on commit 0728b94

Please sign in to comment.