Skip to content

Commit

Permalink
Add Blob Shiv for Android Cordova compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeen committed Aug 14, 2013
1 parent 4c93974 commit 4883aa7
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion WebContent/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,38 @@
*/

(function(obj) {


// Blob Shiv for Android Cordova compatibility
obj.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);
};
}
};
}());

var ERR_BAD_FORMAT = "File format is not recognized.";
var ERR_ENCRYPTED = "File contains encrypted entry.";
var ERR_ZIP64 = "File is using Zip64 (4gb+ file size).";
Expand Down

0 comments on commit 4883aa7

Please sign in to comment.