Skip to content

Commit

Permalink
workaround for new webr format
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Sep 12, 2024
1 parent 195b551 commit 6fcd76e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions routes/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ function tar_index_files(input){
var extract = tar.extract({allowUnknownFormat: true})
.on('entry', process_entry)
.on('finish', finish_stream)
.on('error', reject);
.on('error', function(err){
if (err.message.includes('Unexpected end') && files.length > 0){
finish_stream(); //workaround tar-stream bug for custom webr 0.4.2 tar headers
} else {
reject(err);
}
});


input.pipe(gunzip()).pipe(extract);
});
}
Expand All @@ -66,7 +74,8 @@ send_from_bucket = function(hash, file, res){
if(file === `${name}.index` && name.endsWith('gz')){
return tar_index_files(stream_file(pkg)).then(function(index){
index.files.forEach(function(entry){
entry.filename = entry.filename.match(/\/.*/)[0]; //strip pkg root dir
var newname = entry.filename.match(/\/.*/); //strip pkg root dir
entry.filename = newname ? newname[0] : "unknown";
});
index.gzip = true;
res.send(index);
Expand Down

0 comments on commit 6fcd76e

Please sign in to comment.