Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Blob Shiv for Android Cordova compatibility #70

Open
wants to merge 1 commit into from

2 participants

@thejae

Hi @hugeen am quite new to the github workflow. Did your code ever made it into production version of zipjs? I cant find your code in the latest download package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2013
  1. @hugeen
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 1 deletion.
  1. +32 −1 WebContent/zip.js
View
33 WebContent/zip.js
@@ -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).";
Something went wrong with that request. Please try again.