correctly estimate upload size

This commit is contained in:
ansuz
2017-05-12 12:12:51 +02:00
parent a993ab6616
commit 22efde87d5
2 changed files with 11 additions and 23 deletions

View File

@@ -36,6 +36,7 @@ define([
var key = Nacl.randomBytes(32);
var next = FileCrypto.encrypt(u8, metadata, key);
var estimate = FileCrypto.computeEncryptedSize(blob.byteLength, metadata);
var chunks = [];
var sendChunk = function (box, cb) {
@@ -47,15 +48,21 @@ define([
});
};
var actual = 0;
var again = function (err, box) {
if (err) { throw new Error(err); }
if (box) {
actual += box.length;
return void sendChunk(box, function (e) {
if (e) { return console.error(e); }
next(again);
});
}
if (actual !== estimate) {
console.error('Estimated size does not match actual size');
}
// if not box then done
Cryptpad.rpc.send('UPLOAD_COMPLETE', '', function (e, res) {
if (e) { return void console.error(e); }