Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binary module upload support and code size/limit informational output #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,33 @@ module.exports = function (opt) {
}

function endStream(cb) {
var usedBytes = 0;

files.map(function (file) {
var name = path.basename(file.path).replace(/\.js$/,'');
modules[name] = file.contents.toString('utf-8');
if (file.path.endsWith('.wasm')) {
var name = path.basename(file.path).replace(/\.wasm$/,'');
var encoded = file.contents.toString('base64');
// count the size of the binary module after encoding into base64;
// that's what is checked against the code size limit
usedBytes += encoded.length;
modules[name] = {
binary: encoded
};
} else {
if (!file.path.endsWith('.js')) {
log('unknown file extension, will upload as text: ' + path.basename(file.path))
}
var name = path.basename(file.path).replace(/\.js$/,'');
var encoded = file.contents.toString('utf-8');
usedBytes += encoded.length;
modules[name] = encoded;
}
});

var usedMB = usedBytes / 1024 / 1024;
var usedPercent = 100 * usedMB / 5;
log('Uploading; will use ' + usedMB.toFixed(2) + ' MiB of 5 MiB code size limit (' + usedPercent.toFixed(2) + '%)');

var request = (opt.secure ? https : http).request;
var api = '/api/user/code';
var reqOpts = {
Expand Down