.
WebKit :
https://github.com/WebKit/webkit/blob/master/Source/WebCore/platform/network/BlobRegistryImpl.cpp#L182
Firefox - :
https://hg.mozilla.org/mozilla-central/file/d8e238b811d3/dom/file
.
. .
WebKit, Blob.slice - O (blob.length), startIndex endIndex.
Blob ([b1, b2..]) - O (b1.length + b2.length +...)
URL.createObjectURL Blob, O (1).
Blob , , Blob, . Blob .
Blobs, :
var container = document.getElementById('container');
var getReaderPromise = function(bl) {
var blReader = new FileReader();
return new Promise(function(resolve, reject) {
blReader.onload = function() { resolve(blReader.result) };
blReader.readAsArrayBuffer(bl);
});
}
var showContent = function(arrbuf) {
console.log(String.fromCharCode.apply(null, new Uint8Array(arrbuf)));
}
var foo = new Blob('abcdefghjklmnopqrstuvwxyz'.split(''), {type : 'text/plain'});
var promiseFoo = getReaderPromise(foo);
var foores = undefined;
promiseFoo.then(function(res) {
foores = res;
});
var bar1 = foo.slice(2,10);
var promiseBar1 = getReaderPromise(bar1);
var bar1res = undefined;
promiseBar1.then(function(res) {
bar1res = res;
});
var bar2 = foo.slice(12,20);
var promiseBar2 = getReaderPromise(bar2);
var bar2res = undefined;
promiseBar2.then(function(res) {
bar2res = res;
});
var bars = new Blob([bar1, bar2]);
var promiseBars = getReaderPromise(bars);
var barsres = undefined;
promiseBars.then(function(res) {
barsres = res;
});
Promise.all([promiseFoo, promiseBar1, promiseBar2, promiseBars]).then(function() {
showContent(foores);
showContent(bar1res);
showContent(bar2res);
showContent(barsres);
var bar2arr = new Uint8Array(bar2res);
bar2arr[4] = '2'.charCodeAt();
showContent(bar2res);
showContent(barsres);
showContent(foores);
var url = URL.createObjectURL(bars);
console.log(url);
container.innerHTML += '<iframe src="' + url + '"></iframe>';
var barsarr = new Uint8Array(barsres);
barsarr[4] = '5'.charCodeAt();
container.innerHTML += '<iframe src="' + url + '"></iframe>';
url = URL.createObjectURL(bars);
console.log(url);
container.innerHTML += '<iframe src="' + url + '"></iframe>';
});
(http://www.kurilo.su/stackoverflow/46085675/)
, Blob .
, O (1). , O (n), , WebKit, O (blob.length).