mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Uses blob URL instead of data when possible
This commit is contained in:
parent
4ce6cb8b0f
commit
c8af2565f1
3 changed files with 34 additions and 8 deletions
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref */
|
||||
/* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -1100,6 +1100,33 @@ PDFJS.createBlob = function createBlob(data, contentType) {
|
|||
return bb.getBlob(contentType);
|
||||
};
|
||||
|
||||
PDFJS.createObjectURL = (function createObjectURLClosure() {
|
||||
if (typeof URL !== 'undefined' && URL.createObjectURL) {
|
||||
return function createObjectURL(data, contentType) {
|
||||
var blob = PDFJS.createBlob(data, contentType);
|
||||
return URL.createObjectURL(blob);
|
||||
};
|
||||
}
|
||||
|
||||
// Blob/createObjectURL is not available, falling back to data schema.
|
||||
var digits =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
|
||||
return function createObjectURL(data, contentType) {
|
||||
var buffer = 'data:' + contentType + ';base64,';
|
||||
for (var i = 0, ii = data.length; i < ii; i += 3) {
|
||||
var b1 = data[i] & 0xFF;
|
||||
var b2 = data[i + 1] & 0xFF;
|
||||
var b3 = data[i + 2] & 0xFF;
|
||||
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
||||
var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
||||
var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
|
||||
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
})();
|
||||
|
||||
function MessageHandler(name, comObj) {
|
||||
this.name = name;
|
||||
this.comObj = comObj;
|
||||
|
@ -1191,10 +1218,10 @@ MessageHandler.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function loadJpegStream(id, imageData, objs) {
|
||||
function loadJpegStream(id, imageUrl, objs) {
|
||||
var img = new Image();
|
||||
img.onload = (function loadJpegStream_onloadClosure() {
|
||||
objs.resolve(id, img);
|
||||
});
|
||||
img.src = 'data:image/jpeg;base64,' + window.btoa(imageData);
|
||||
img.src = imageUrl;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue