32 lines
947 B
JavaScript
32 lines
947 B
JavaScript
Blob = (function() {
|
|
var nativeBlob = Blob;
|
|
|
|
// Add unprefixed slice() method.
|
|
if (Blob.prototype.webkitSlice) {
|
|
Blob.prototype.slice = Blob.prototype.webkitSlice;
|
|
}
|
|
else if (Blob.prototype.mozSlice) {
|
|
Blob.prototype.slice = Blob.prototype.mozSlice;
|
|
}
|
|
|
|
// Temporarily replace Blob() constructor with one that checks support.
|
|
return function(parts, properties) {
|
|
try {
|
|
// Restore native Blob() constructor, so this check is only evaluated once.
|
|
Blob = nativeBlob;
|
|
return new Blob(parts || [], properties || {});
|
|
}
|
|
catch (e) {
|
|
// If construction fails provide one that uses BlobBuilder.
|
|
Blob = function (parts, properties) {
|
|
var bb = new (WebKitBlobBuilder || MozBlobBuilder), i;
|
|
for (i in parts) {
|
|
bb.append(parts[i]);
|
|
}
|
|
|
|
return bb.getBlob(properties && properties.type ? properties.type : undefined);
|
|
};
|
|
}
|
|
};
|
|
}());
|