Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
9416cd37
Commit
9416cd37
authored
11 years ago
by
Chris Rebert
Browse files
Options
Download
Email Patches
Plain Diff
update to latest jszip
commit 04fc93045334dc1b679aba5c2dce206da777a85c 2013-10-12T12:39:56-07:00
parent
3abe86b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs-assets/js/jszip.js
+99
-57
docs-assets/js/jszip.js
with
99 additions
and
57 deletions
+99
-57
docs-assets/js/jszip.js
+
99
-
57
View file @
9416cd37
...
@@ -58,8 +58,62 @@ JSZip.defaults = {
...
@@ -58,8 +58,62 @@ JSZip.defaults = {
compression
:
null
compression
:
null
};
};
/*
* List features that require a modern browser, and if the current browser support them.
*/
JSZip
.
support
=
{
// contains true if JSZip can read/generate ArrayBuffer, false otherwise.
arraybuffer
:
(
function
(){
return
typeof
ArrayBuffer
!==
"
undefined
"
&&
typeof
Uint8Array
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate nodejs Buffer, false otherwise.
nodebuffer
:
(
function
(){
return
typeof
Buffer
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate Uint8Array, false otherwise.
uint8array
:
(
function
(){
return
typeof
Uint8Array
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate Blob, false otherwise.
blob
:
(
function
(){
// the spec started with BlobBuilder then replaced it with a construtor for Blob.
// Result : we have browsers that :
// * know the BlobBuilder (but with prefix)
// * know the Blob constructor
// * know about Blob but not about how to build them
// About the "=== 0" test : if given the wrong type, it may be converted to a string.
// Instead of an empty content, we will get "[object Uint8Array]" for example.
if
(
typeof
ArrayBuffer
===
"
undefined
"
)
{
return
false
;
}
var
buffer
=
new
ArrayBuffer
(
0
);
try
{
return
new
Blob
([
buffer
],
{
type
:
"
application/zip
"
}).
size
===
0
;
}
catch
(
e
)
{}
try
{
var
builder
=
new
(
window
.
BlobBuilder
||
window
.
WebKitBlobBuilder
||
window
.
MozBlobBuilder
||
window
.
MSBlobBuilder
)();
builder
.
append
(
buffer
);
return
builder
.
getBlob
(
'
application/zip
'
).
size
===
0
;
}
catch
(
e
)
{}
return
false
;
})()
};
JSZip
.
prototype
=
(
function
()
{
JSZip
.
prototype
=
(
function
()
{
var
textEncoder
,
textDecoder
;
if
(
JSZip
.
support
.
uint8array
&&
typeof
TextEncoder
===
"
function
"
&&
typeof
TextDecoder
===
"
function
"
)
{
textEncoder
=
new
TextEncoder
(
"
utf-8
"
);
textDecoder
=
new
TextDecoder
(
"
utf-8
"
);
}
/**
/**
* Returns the raw data of a ZipObject, decompress the content if necessary.
* Returns the raw data of a ZipObject, decompress the content if necessary.
...
@@ -97,8 +151,8 @@ JSZip.prototype = (function () {
...
@@ -97,8 +151,8 @@ JSZip.prototype = (function () {
if
(
!
file
.
options
.
binary
)
{
if
(
!
file
.
options
.
binary
)
{
// unicode text !
// unicode text !
// unicode string => binary string is a painful process, check if we can avoid it.
// unicode string => binary string is a painful process, check if we can avoid it.
if
(
JSZip
.
support
.
uint8array
&&
typeof
TextEncoder
===
"
function
"
)
{
if
(
textEncoder
)
{
return
T
extEncoder
(
"
utf-8
"
)
.
encode
(
result
);
return
t
extEncoder
.
encode
(
result
);
}
}
if
(
JSZip
.
support
.
nodebuffer
)
{
if
(
JSZip
.
support
.
nodebuffer
)
{
return
new
Buffer
(
result
,
"
utf-8
"
);
return
new
Buffer
(
result
,
"
utf-8
"
);
...
@@ -557,7 +611,7 @@ JSZip.prototype = (function () {
...
@@ -557,7 +611,7 @@ JSZip.prototype = (function () {
*/
*/
file
:
function
(
name
,
data
,
o
)
{
file
:
function
(
name
,
data
,
o
)
{
if
(
arguments
.
length
===
1
)
{
if
(
arguments
.
length
===
1
)
{
if
(
name
instanceof
RegExp
)
{
if
(
JSZip
.
utils
.
isRegExp
(
name
)
)
{
var
regexp
=
name
;
var
regexp
=
name
;
return
this
.
filter
(
function
(
relativePath
,
file
)
{
return
this
.
filter
(
function
(
relativePath
,
file
)
{
return
!
file
.
options
.
dir
&&
regexp
.
test
(
relativePath
);
return
!
file
.
options
.
dir
&&
regexp
.
test
(
relativePath
);
...
@@ -584,7 +638,7 @@ JSZip.prototype = (function () {
...
@@ -584,7 +638,7 @@ JSZip.prototype = (function () {
return
this
;
return
this
;
}
}
if
(
arg
instanceof
RegExp
)
{
if
(
JSZip
.
utils
.
is
RegExp
(
arg
)
)
{
return
this
.
filter
(
function
(
relativePath
,
file
)
{
return
this
.
filter
(
function
(
relativePath
,
file
)
{
return
file
.
options
.
dir
&&
arg
.
test
(
relativePath
);
return
file
.
options
.
dir
&&
arg
.
test
(
relativePath
);
});
});
...
@@ -854,8 +908,8 @@ JSZip.prototype = (function () {
...
@@ -854,8 +908,8 @@ JSZip.prototype = (function () {
// TextEncoder + Uint8Array to binary string is faster than checking every bytes on long strings.
// TextEncoder + Uint8Array to binary string is faster than checking every bytes on long strings.
// http://jsperf.com/utf8encode-vs-textencoder
// http://jsperf.com/utf8encode-vs-textencoder
// On short strings (file names for example), the TextEncoder API is (currently) slower.
// On short strings (file names for example), the TextEncoder API is (currently) slower.
if
(
JSZip
.
support
.
uint8array
&&
typeof
TextEncoder
===
"
function
"
)
{
if
(
textEncoder
)
{
var
u8
=
T
extEncoder
(
"
utf-8
"
)
.
encode
(
string
);
var
u8
=
t
extEncoder
.
encode
(
string
);
return
JSZip
.
utils
.
transformTo
(
"
string
"
,
u8
);
return
JSZip
.
utils
.
transformTo
(
"
string
"
,
u8
);
}
}
if
(
JSZip
.
support
.
nodebuffer
)
{
if
(
JSZip
.
support
.
nodebuffer
)
{
...
@@ -898,8 +952,8 @@ JSZip.prototype = (function () {
...
@@ -898,8 +952,8 @@ JSZip.prototype = (function () {
// check if we can use the TextDecoder API
// check if we can use the TextDecoder API
// see http://encoding.spec.whatwg.org/#api
// see http://encoding.spec.whatwg.org/#api
if
(
JSZip
.
support
.
uint8array
&&
typeof
TextDecoder
===
"
function
"
)
{
if
(
textDecoder
)
{
return
T
extDecoder
(
"
utf-8
"
)
.
decode
(
return
t
extDecoder
.
decode
(
JSZip
.
utils
.
transformTo
(
"
uint8array
"
,
input
)
JSZip
.
utils
.
transformTo
(
"
uint8array
"
,
input
)
);
);
}
}
...
@@ -960,52 +1014,6 @@ JSZip.compressions = {
...
@@ -960,52 +1014,6 @@ JSZip.compressions = {
}
}
};
};
/*
* List features that require a modern browser, and if the current browser support them.
*/
JSZip
.
support
=
{
// contains true if JSZip can read/generate ArrayBuffer, false otherwise.
arraybuffer
:
(
function
(){
return
typeof
ArrayBuffer
!==
"
undefined
"
&&
typeof
Uint8Array
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate nodejs Buffer, false otherwise.
nodebuffer
:
(
function
(){
return
typeof
Buffer
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate Uint8Array, false otherwise.
uint8array
:
(
function
(){
return
typeof
Uint8Array
!==
"
undefined
"
;
})(),
// contains true if JSZip can read/generate Blob, false otherwise.
blob
:
(
function
(){
// the spec started with BlobBuilder then replaced it with a construtor for Blob.
// Result : we have browsers that :
// * know the BlobBuilder (but with prefix)
// * know the Blob constructor
// * know about Blob but not about how to build them
// About the "=== 0" test : if given the wrong type, it may be converted to a string.
// Instead of an empty content, we will get "[object Uint8Array]" for example.
if
(
typeof
ArrayBuffer
===
"
undefined
"
)
{
return
false
;
}
var
buffer
=
new
ArrayBuffer
(
0
);
try
{
return
new
Blob
([
buffer
],
{
type
:
"
application/zip
"
}).
size
===
0
;
}
catch
(
e
)
{}
try
{
var
builder
=
new
(
window
.
BlobBuilder
||
window
.
WebKitBlobBuilder
||
window
.
MozBlobBuilder
||
window
.
MSBlobBuilder
)();
builder
.
append
(
buffer
);
return
builder
.
getBlob
(
'
application/zip
'
).
size
===
0
;
}
catch
(
e
)
{}
return
false
;
})()
};
(
function
()
{
(
function
()
{
JSZip
.
utils
=
{
JSZip
.
utils
=
{
/**
/**
...
@@ -1120,12 +1128,36 @@ JSZip.support = {
...
@@ -1120,12 +1128,36 @@ JSZip.support = {
var
chunk
=
65536
;
var
chunk
=
65536
;
var
result
=
[],
len
=
array
.
length
,
type
=
JSZip
.
utils
.
getTypeOf
(
array
),
k
=
0
;
var
result
=
[],
len
=
array
.
length
,
type
=
JSZip
.
utils
.
getTypeOf
(
array
),
k
=
0
;
var
canUseApply
=
true
;
try
{
switch
(
type
)
{
case
"
uint8array
"
:
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
0
));
break
;
case
"
nodebuffer
"
:
String
.
fromCharCode
.
apply
(
null
,
new
Buffer
(
0
));
break
;
}
}
catch
(
e
)
{
canUseApply
=
false
;
}
// no apply : slow and painful algorithm
// default browser on android 4.*
if
(
!
canUseApply
)
{
var
resultStr
=
""
;
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
resultStr
+=
String
.
fromCharCode
(
array
[
i
]);
}
return
resultStr
;
}
while
(
k
<
len
&&
chunk
>
1
)
{
while
(
k
<
len
&&
chunk
>
1
)
{
try
{
try
{
if
(
type
===
"
array
"
||
type
===
"
nodebuffer
"
)
{
if
(
type
===
"
array
"
||
type
===
"
nodebuffer
"
)
{
result
.
push
(
String
.
fromCharCode
.
apply
(
null
,
array
.
slice
(
k
,
Math
.
m
ax
(
k
+
chunk
,
len
))));
result
.
push
(
String
.
fromCharCode
.
apply
(
null
,
array
.
slice
(
k
,
Math
.
m
in
(
k
+
chunk
,
len
))));
}
else
{
}
else
{
result
.
push
(
String
.
fromCharCode
.
apply
(
null
,
array
.
subarray
(
k
,
k
+
chunk
)));
result
.
push
(
String
.
fromCharCode
.
apply
(
null
,
array
.
subarray
(
k
,
Math
.
min
(
k
+
chunk
,
len
)
)));
}
}
k
+=
chunk
;
k
+=
chunk
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -1263,7 +1295,7 @@ JSZip.support = {
...
@@ -1263,7 +1295,7 @@ JSZip.support = {
if
(
typeof
input
===
"
string
"
)
{
if
(
typeof
input
===
"
string
"
)
{
return
"
string
"
;
return
"
string
"
;
}
}
if
(
input
instanceof
Array
)
{
if
(
Object
.
prototype
.
toString
.
call
(
input
)
===
"
[object
Array
]
"
)
{
return
"
array
"
;
return
"
array
"
;
}
}
if
(
JSZip
.
support
.
nodebuffer
&&
Buffer
.
isBuffer
(
input
))
{
if
(
JSZip
.
support
.
nodebuffer
&&
Buffer
.
isBuffer
(
input
))
{
...
@@ -1277,6 +1309,16 @@ JSZip.support = {
...
@@ -1277,6 +1309,16 @@ JSZip.support = {
}
}
};
};
/**
* Cross-window, cross-Node-context regular expression detection
* @param {Object} object Anything
* @return {Boolean} true if the object is a regular expression,
* false otherwise
*/
JSZip
.
utils
.
isRegExp
=
function
(
object
)
{
return
Object
.
prototype
.
toString
.
call
(
object
)
===
"
[object RegExp]
"
;
};
/**
/**
* Throw an exception if the type is not supported.
* Throw an exception if the type is not supported.
* @param {String} type the type to check.
* @param {String} type the type to check.
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment