/**
|
|
* Create a blob builder even when vendor prefixes exist
|
|
*/
|
|
|
|
var BlobBuilder = global.BlobBuilder
|
|
|| global.WebKitBlobBuilder
|
|
|| global.MSBlobBuilder
|
|
|| global.MozBlobBuilder;
|
|
|
|
/**
|
|
* Check if Blob constructor is supported
|
|
*/
|
|
|
|
var blobSupported = (function() {
|
|
try {
|
|
var b = new Blob(['hi']);
|
|
return b.size == 2;
|
|
} catch(e) {
|
|
return false;
|
|
}
|
|
})();
|
|
|
|
/**
|
|
* Check if BlobBuilder is supported
|
|
*/
|
|
|
|
var blobBuilderSupported = BlobBuilder
|
|
&& BlobBuilder.prototype.append
|
|
&& BlobBuilder.prototype.getBlob;
|
|
|
|
function BlobBuilderConstructor(ary, options) {
|
|
options = options || {};
|
|
|
|
var bb = new BlobBuilder();
|
|
for (var i = 0; i < ary.length; i++) {
|
|
bb.append(ary[i]);
|
|
}
|
|
return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
|
|
};
|
|
|
|
module.exports = (function() {
|
|
if (blobSupported) {
|
|
return global.Blob;
|
|
} else if (blobBuilderSupported) {
|
|
return BlobBuilderConstructor;
|
|
} else {
|
|
return undefined;
|
|
}
|
|
})();
|