forked from Kieran/void.cat
Report hash speed
This commit is contained in:
parent
5c955712e1
commit
51b56fd4d3
@ -30,7 +30,6 @@ export function FileUpload(props) {
|
|||||||
const calc = new RateCalculator();
|
const calc = new RateCalculator();
|
||||||
|
|
||||||
function handleProgress(e) {
|
function handleProgress(e) {
|
||||||
console.log(e);
|
|
||||||
if (e instanceof ProgressEvent) {
|
if (e instanceof ProgressEvent) {
|
||||||
let newProgress = e.loaded / e.total;
|
let newProgress = e.loaded / e.total;
|
||||||
|
|
||||||
@ -139,6 +138,7 @@ export function FileUpload(props) {
|
|||||||
|
|
||||||
setUState(UploadState.Hashing);
|
setUState(UploadState.Hashing);
|
||||||
let hash = await digest(props.file);
|
let hash = await digest(props.file);
|
||||||
|
calc.Reset();
|
||||||
if(props.file.size >= uploadSize) {
|
if(props.file.size >= uploadSize) {
|
||||||
await doSplitXHRUpload(hash, uploadSize);
|
await doSplitXHRUpload(hash, uploadSize);
|
||||||
} else {
|
} else {
|
||||||
@ -152,7 +152,7 @@ export function FileUpload(props) {
|
|||||||
setProgress(0);
|
setProgress(0);
|
||||||
const segments = Math.ceil(props.file.size / splitSize);
|
const segments = Math.ceil(props.file.size / splitSize);
|
||||||
for (let s = 0; s < segments; s++) {
|
for (let s = 0; s < segments; s++) {
|
||||||
calc.ResetLastLoaded();
|
calc.Reset();
|
||||||
let offset = s * splitSize;
|
let offset = s * splitSize;
|
||||||
let slice = props.file.slice(offset, offset + splitSize, props.file.type);
|
let slice = props.file.slice(offset, offset + splitSize, props.file.type);
|
||||||
let segment = await slice.arrayBuffer();
|
let segment = await slice.arrayBuffer();
|
||||||
@ -176,13 +176,16 @@ export function FileUpload(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function digest(file) {
|
async function digest(file) {
|
||||||
const chunkSize = 10_000_000;
|
const chunkSize = 100_000_000;
|
||||||
let sha = CryptoJS.algo.SHA256.create();
|
let sha = CryptoJS.algo.SHA256.create();
|
||||||
for (let x = 0; x < Math.ceil(file.size / chunkSize); x++) {
|
for (let x = 0; x < Math.ceil(file.size / chunkSize); x++) {
|
||||||
let offset = x * chunkSize;
|
let offset = x * chunkSize;
|
||||||
let slice = file.slice(offset, offset + chunkSize, file.type);
|
let slice = file.slice(offset, offset + chunkSize, file.type);
|
||||||
let data = Uint32Array.from(await slice.arrayBuffer());
|
let data = Uint32Array.from(await slice.arrayBuffer());
|
||||||
sha.update(new CryptoJS.lib.WordArray.init(data, slice.length));
|
sha.update(new CryptoJS.lib.WordArray.init(data, slice.length));
|
||||||
|
|
||||||
|
calc.ReportLoaded(offset);
|
||||||
|
setSpeed(calc.RateWindow(5));
|
||||||
setProgress(offset / parseFloat(file.size));
|
setProgress(offset / parseFloat(file.size));
|
||||||
}
|
}
|
||||||
return sha.finalize().toString();
|
return sha.finalize().toString();
|
||||||
|
@ -4,7 +4,8 @@ export class RateCalculator {
|
|||||||
this.lastLoaded = 0;
|
this.lastLoaded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetLastLoaded() {
|
Reset() {
|
||||||
|
this.reports = [];
|
||||||
this.lastLoaded = 0;
|
this.lastLoaded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user