Add support for fixed_chunk_size to async Range downloads (#755)
This commit is contained in:
parent
875e01202c
commit
7f5fb11faf
|
@ -441,7 +441,7 @@ V86Starter.prototype.continue_init = async function(emulator, options)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buffer = new v86util.AsyncXHRBuffer(file.url, file.size);
|
buffer = new v86util.AsyncXHRBuffer(file.url, file.size, file.fixed_chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
files_to_load.push({
|
files_to_load.push({
|
||||||
|
|
|
@ -94,8 +94,9 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {string} filename Name of the file to download
|
* @param {string} filename Name of the file to download
|
||||||
* @param {number|undefined} size
|
* @param {number|undefined} size
|
||||||
|
* @param {number|undefined} fixed_chunk_size
|
||||||
*/
|
*/
|
||||||
function AsyncXHRBuffer(filename, size)
|
function AsyncXHRBuffer(filename, size, fixed_chunk_size)
|
||||||
{
|
{
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
|
|
||||||
|
@ -104,6 +105,9 @@
|
||||||
this.block_cache = new Map();
|
this.block_cache = new Map();
|
||||||
this.block_cache_is_write = new Set();
|
this.block_cache_is_write = new Set();
|
||||||
|
|
||||||
|
this.fixed_chunk_size = fixed_chunk_size;
|
||||||
|
this.cache_reads = !!fixed_chunk_size; // TODO: could also be useful in other cases (needs testing)
|
||||||
|
|
||||||
this.onload = undefined;
|
this.onload = undefined;
|
||||||
this.onprogress = undefined;
|
this.onprogress = undefined;
|
||||||
}
|
}
|
||||||
|
@ -194,14 +198,29 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var requested_start = offset;
|
||||||
|
var requested_length = len;
|
||||||
|
if(this.fixed_chunk_size)
|
||||||
|
{
|
||||||
|
requested_start = offset - (offset % this.fixed_chunk_size);
|
||||||
|
requested_length = Math.ceil((offset - requested_start + len) / this.fixed_chunk_size) * this.fixed_chunk_size;
|
||||||
|
}
|
||||||
|
|
||||||
v86util.load_file(this.filename, {
|
v86util.load_file(this.filename, {
|
||||||
done: function done(buffer)
|
done: function done(buffer)
|
||||||
{
|
{
|
||||||
var block = new Uint8Array(buffer);
|
var block = new Uint8Array(buffer);
|
||||||
this.handle_read(offset, len, block);
|
this.handle_read(requested_start, requested_length, block);
|
||||||
fn(block);
|
if(requested_start == offset && requested_length == len)
|
||||||
|
{
|
||||||
|
fn(block);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fn(block.subarray(offset - requested_start, offset - requested_start + len));
|
||||||
|
}
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
range: { start: offset, length: len },
|
range: { start: requested_start, length: requested_length },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue