mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
help chrome gc by reusing one filereader
This commit is contained in:
parent
50a477ee47
commit
539e7b8efe
|
@ -8,7 +8,7 @@ function hex2u8(txt) {
|
||||||
|
|
||||||
var subtle = null;
|
var subtle = null;
|
||||||
try {
|
try {
|
||||||
subtle = crypto.subtle || crypto.webkitSubtle;
|
subtle = crypto.subtle;
|
||||||
subtle.digest('SHA-512', new Uint8Array(1)).then(
|
subtle.digest('SHA-512', new Uint8Array(1)).then(
|
||||||
function (x) { },
|
function (x) { },
|
||||||
function (x) { load_fb(); }
|
function (x) { load_fb(); }
|
||||||
|
@ -23,11 +23,20 @@ function load_fb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var reader = null,
|
||||||
|
busy = false;
|
||||||
|
|
||||||
|
|
||||||
onmessage = (d) => {
|
onmessage = (d) => {
|
||||||
var [nchunk, fobj, car, cdr] = d.data,
|
if (busy)
|
||||||
t0 = Date.now(),
|
return postMessage(["panic", 'worker got another task while busy']);
|
||||||
|
|
||||||
|
if (!reader)
|
||||||
reader = new FileReader();
|
reader = new FileReader();
|
||||||
|
|
||||||
|
var [nchunk, fobj, car, cdr] = d.data,
|
||||||
|
t0 = Date.now();
|
||||||
|
|
||||||
reader.onload = function (e) {
|
reader.onload = function (e) {
|
||||||
try {
|
try {
|
||||||
//console.log('[ w] %d HASH bgin', nchunk);
|
//console.log('[ w] %d HASH bgin', nchunk);
|
||||||
|
@ -49,12 +58,14 @@ onmessage = (d) => {
|
||||||
postMessage(["ferr", err]);
|
postMessage(["ferr", err]);
|
||||||
};
|
};
|
||||||
//console.log('[ w] %d read bgin', nchunk);
|
//console.log('[ w] %d read bgin', nchunk);
|
||||||
|
busy = true;
|
||||||
reader.readAsArrayBuffer(
|
reader.readAsArrayBuffer(
|
||||||
File.prototype.slice.call(fobj, car, cdr));
|
File.prototype.slice.call(fobj, car, cdr));
|
||||||
|
|
||||||
|
|
||||||
var hash_calc = function (buf) {
|
var hash_calc = function (buf) {
|
||||||
var hash_done = function (hashbuf) {
|
var hash_done = function (hashbuf) {
|
||||||
|
busy = false;
|
||||||
try {
|
try {
|
||||||
var hslice = new Uint8Array(hashbuf).subarray(0, 33);
|
var hslice = new Uint8Array(hashbuf).subarray(0, 33);
|
||||||
//console.log('[ w] %d HASH DONE', nchunk);
|
//console.log('[ w] %d HASH DONE', nchunk);
|
||||||
|
|
Loading…
Reference in a new issue