try to estimate upload size

pull/1/head
ansuz 8 years ago
parent 6d30d7f89f
commit 5d37a50a87

@ -7,6 +7,17 @@ define([
var plainChunkLength = 128 * 1024; var plainChunkLength = 128 * 1024;
var cypherChunkLength = 131088; var cypherChunkLength = 131088;
var computeEncryptedSize = function (bytes, meta) {
var metasize = Nacl.util.decodeUTF8(meta).length + 18;
var chunks = Math.ceil(bytes / plainChunkLength);
console.log({
metasize: metasize,
chunks: chunks,
bytes: bytes,
});
return metasize + (chunks * 16) + bytes;
};
var encodePrefix = function (p) { var encodePrefix = function (p) {
return [ return [
65280, // 255 << 8 65280, // 255 << 8
@ -159,6 +170,11 @@ define([
var prefixed = new Uint8Array(encodePrefix(box.length) var prefixed = new Uint8Array(encodePrefix(box.length)
.concat(slice(box))); .concat(slice(box)));
state++; state++;
// TODO verify that each box is the expected size
console.log(part.length, prefixed.length);
return void cb(void 0, prefixed); return void cb(void 0, prefixed);
} }
@ -171,6 +187,8 @@ define([
increment(nonce); increment(nonce);
i++; i++;
console.log(part.length, box.length);
// regular data is done // regular data is done
if (i * plainChunkLength >= u8.length) { state = 2; } if (i * plainChunkLength >= u8.length) { state = 2; }
@ -184,5 +202,6 @@ define([
decrypt: decrypt, decrypt: decrypt,
encrypt: encrypt, encrypt: encrypt,
joinChunks: joinChunks, joinChunks: joinChunks,
computeEncryptedSize: computeEncryptedSize,
}; };
}); });

Loading…
Cancel
Save