mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-05 15:32:56 +02:00
Initial commit
This commit is contained in:
parent
26dd81b2df
commit
993289d86b
51 changed files with 16863 additions and 0 deletions
31
files_reader/js/libs/blob.js
Normal file
31
files_reader/js/libs/blob.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
};
|
||||
}
|
||||
};
|
||||
}());
|
2163
files_reader/js/libs/inflate.js
Normal file
2163
files_reader/js/libs/inflate.js
Normal file
File diff suppressed because it is too large
Load diff
4
files_reader/js/libs/jquery-2.1.0.min.js
vendored
Normal file
4
files_reader/js/libs/jquery-2.1.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
4
files_reader/js/libs/jquery.finger.0.1.2.js
Normal file
4
files_reader/js/libs/jquery.finger.0.1.2.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*! jquery.finger - v0.1.2 - 2014-10-01
|
||||
* https://github.com/ngryman/jquery.finger
|
||||
* Copyright (c) 2014 Nicolas Gryman; Licensed MIT */
|
||||
(function(e,t){function a(t){t.preventDefault(),e.event.remove(T,"click",a)}function n(e,t){return(p?t.originalEvent.touches[0]:t)["page"+e.toUpperCase()]}function r(t,n,r){var o=e.Event(n,b);e.event.trigger(o,{originalEvent:t},t.target),o.isDefaultPrevented()&&(~n.indexOf("tap")&&!p?e.event.add(T,"click",a):t.preventDefault()),r&&(e.event.remove(T,y+"."+D,i),e.event.remove(T,x+"."+D,d))}function o(t){var o=t.timeStamp||+new Date;v!=o&&(v=o,k.x=b.x=n("x",t),k.y=b.y=n("y",t),k.time=o,k.target=t.target,b.orientation=null,b.end=!1,u=!1,l=!1,c=setTimeout(function(){l=!0,r(t,"press")},e.Finger.pressDuration),e.event.add(T,y+"."+D,i),e.event.add(T,x+"."+D,d),w.preventDefault&&(t.preventDefault(),e.event.add(T,"click",a)))}function i(t){if(b.x=n("x",t),b.y=n("y",t),b.dx=b.x-k.x,b.dy=b.y-k.y,b.adx=Math.abs(b.dx),b.ady=Math.abs(b.dy),u=b.adx>w.motionThreshold||b.ady>w.motionThreshold){for(clearTimeout(c),b.orientation||(b.adx>b.ady?(b.orientation="horizontal",b.direction=b.dx>0?1:-1):(b.orientation="vertical",b.direction=b.dy>0?1:-1));t.target&&t.target!==k.target;)t.target=t.target.parentNode;return t.target!==k.target?(t.target=k.target,d.call(this,e.Event(x+"."+D,t)),void 0):(r(t,"drag"),void 0)}}function d(e){var t,a=e.timeStamp||+new Date,n=a-k.time;if(clearTimeout(c),u||l||e.target!==k.target)e.target=k.target,w.flickDuration>n&&r(e,"flick"),b.end=!0,t="drag";else{var o=g===e.target&&w.doubleTapInterval>a-s;t=o?"doubletap":"tap",g=o?null:k.target,s=a}r(e,t,!0)}var u,l,v,c,g,s,m=/chrome/i.exec(t),f=/android/i.exec(t),p="ontouchstart"in window&&!(m&&!f),h=p?"touchstart":"mousedown",x=p?"touchend touchcancel":"mouseup mouseleave",y=p?"touchmove":"mousemove",D="finger",T=e("html")[0],k={},b={},w=e.Finger={pressDuration:300,doubleTapInterval:300,flickDuration:150,motionThreshold:5};e.event.add(T,h+"."+D,o)})(jQuery,navigator.userAgent);
|
108
files_reader/js/libs/jquery.highlight.js
Normal file
108
files_reader/js/libs/jquery.highlight.js
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* jQuery Highlight plugin
|
||||
*
|
||||
* Based on highlight v3 by Johann Burkard
|
||||
* http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
|
||||
*
|
||||
* Code a little bit refactored and cleaned (in my humble opinion).
|
||||
* Most important changes:
|
||||
* - has an option to highlight only entire words (wordsOnly - false by default),
|
||||
* - has an option to be case sensitive (caseSensitive - false by default)
|
||||
* - highlight element tag and class names can be specified in options
|
||||
*
|
||||
* Usage:
|
||||
* // wrap every occurrance of text 'lorem' in content
|
||||
* // with <span class='highlight'> (default options)
|
||||
* $('#content').highlight('lorem');
|
||||
*
|
||||
* // search for and highlight more terms at once
|
||||
* // so you can save some time on traversing DOM
|
||||
* $('#content').highlight(['lorem', 'ipsum']);
|
||||
* $('#content').highlight('lorem ipsum');
|
||||
*
|
||||
* // search only for entire word 'lorem'
|
||||
* $('#content').highlight('lorem', { wordsOnly: true });
|
||||
*
|
||||
* // don't ignore case during search of term 'lorem'
|
||||
* $('#content').highlight('lorem', { caseSensitive: true });
|
||||
*
|
||||
* // wrap every occurrance of term 'ipsum' in content
|
||||
* // with <em class='important'>
|
||||
* $('#content').highlight('ipsum', { element: 'em', className: 'important' });
|
||||
*
|
||||
* // remove default highlight
|
||||
* $('#content').unhighlight();
|
||||
*
|
||||
* // remove custom highlight
|
||||
* $('#content').unhighlight({ element: 'em', className: 'important' });
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2009 Bartek Szopka
|
||||
*
|
||||
* Licensed under MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
jQuery.extend({
|
||||
highlight: function (node, re, nodeName, className) {
|
||||
if (node.nodeType === 3) {
|
||||
var match = node.data.match(re);
|
||||
if (match) {
|
||||
var highlight = document.createElement(nodeName || 'span');
|
||||
highlight.className = className || 'highlight';
|
||||
var wordNode = node.splitText(match.index);
|
||||
wordNode.splitText(match[0].length);
|
||||
var wordClone = wordNode.cloneNode(true);
|
||||
highlight.appendChild(wordClone);
|
||||
wordNode.parentNode.replaceChild(highlight, wordNode);
|
||||
return 1; //skip added node in parent
|
||||
}
|
||||
} else if ((node.nodeType === 1 && node.childNodes) && // only element nodes that have children
|
||||
!/(script|style)/i.test(node.tagName) && // ignore script and style nodes
|
||||
!(node.tagName === nodeName.toUpperCase() && node.className === className)) { // skip if already highlighted
|
||||
for (var i = 0; i < node.childNodes.length; i++) {
|
||||
i += jQuery.highlight(node.childNodes[i], re, nodeName, className);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.fn.unhighlight = function (options) {
|
||||
var settings = { className: 'highlight', element: 'span' };
|
||||
jQuery.extend(settings, options);
|
||||
|
||||
return this.find(settings.element + "." + settings.className).each(function () {
|
||||
var parent = this.parentNode;
|
||||
parent.replaceChild(this.firstChild, this);
|
||||
parent.normalize();
|
||||
}).end();
|
||||
};
|
||||
|
||||
jQuery.fn.highlight = function (words, options) {
|
||||
var settings = { className: 'highlight', element: 'span', caseSensitive: false, wordsOnly: false };
|
||||
jQuery.extend(settings, options);
|
||||
|
||||
if (words.constructor === String) {
|
||||
words = [words];
|
||||
}
|
||||
words = jQuery.grep(words, function(word, i){
|
||||
return word != '';
|
||||
});
|
||||
words = jQuery.map(words, function(word, i) {
|
||||
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
});
|
||||
if (words.length == 0) { return this; };
|
||||
|
||||
var flag = settings.caseSensitive ? "" : "i";
|
||||
var pattern = "(" + words.join("|") + ")";
|
||||
if (settings.wordsOnly) {
|
||||
pattern = "\\b" + pattern + "\\b";
|
||||
}
|
||||
var re = new RegExp(pattern, flag);
|
||||
|
||||
return this.each(function () {
|
||||
jQuery.highlight(this, re, settings.element, settings.className);
|
||||
});
|
||||
};
|
||||
|
1001
files_reader/js/libs/mime-types.js
Normal file
1001
files_reader/js/libs/mime-types.js
Normal file
File diff suppressed because it is too large
Load diff
7
files_reader/js/libs/screenfull.min.js
vendored
Normal file
7
files_reader/js/libs/screenfull.min.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*!
|
||||
* screenfull
|
||||
* v1.1.0 - 2013-09-06
|
||||
* https://github.com/sindresorhus/screenfull.js
|
||||
* (c) Sindre Sorhus; MIT License
|
||||
*/
|
||||
!function(a,b){"use strict";var c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var a,c,d=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenchange","MSFullscreenerror"]],e=0,f=d.length,g={};f>e;e++)if(a=d[e],a&&a[1]in b){for(e=0,c=a.length;c>e;e++)g[d[0][e]]=a[e];return g}return!1}(),e={request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,/5\.1[\.\d]* Safari/.test(navigator.userAgent)?a[e]():a[e](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){},raw:d};return d?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!b[d.fullscreenElement]}},element:{enumerable:!0,get:function(){return b[d.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!b[d.fullscreenEnabled]}}}),b.addEventListener(d.fullscreenchange,function(a){e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e,void 0):(a.screenfull=!1,void 0)}(window,document);
|
629
files_reader/js/libs/typedarray.js
Normal file
629
files_reader/js/libs/typedarray.js
Normal file
|
@ -0,0 +1,629 @@
|
|||
/*
|
||||
$LicenseInfo:firstyear=2010&license=mit$
|
||||
|
||||
Copyright (c) 2010, Linden Research, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
$/LicenseInfo$
|
||||
*/
|
||||
/*global document*/
|
||||
|
||||
//
|
||||
// ES3/ES5 implementation of the Krhonos TypedArray Working Draft (work in progress):
|
||||
// Ref: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html
|
||||
// Date: 2011-02-01
|
||||
//
|
||||
// Variations:
|
||||
// * Float/Double -> Float32/Float64, per WebGL-Public mailing list conversations (post 5/17)
|
||||
// * Allows typed_array.get/set() as alias for subscripts (typed_array[])
|
||||
|
||||
var ArrayBuffer, ArrayBufferView,
|
||||
Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array,
|
||||
DataView;
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
/*jslint bitwise: false, nomen: false */
|
||||
|
||||
// Approximations of internal ECMAScript conversion functions
|
||||
var ECMAScript = {
|
||||
ToInt32: function (v) { return v >> 0; },
|
||||
ToUint32: function (v) { return v >>> 0; }
|
||||
};
|
||||
|
||||
// Raise an INDEX_SIZE_ERR event - intentionally induces a DOM error
|
||||
function raise_INDEX_SIZE_ERR() {
|
||||
if (document) {
|
||||
// raises DOMException(INDEX_SIZE_ERR)
|
||||
document.createTextNode("").splitText(1);
|
||||
}
|
||||
throw new RangeError("INDEX_SIZE_ERR");
|
||||
}
|
||||
|
||||
// ES5: lock down object properties
|
||||
function configureProperties(obj) {
|
||||
if (Object.getOwnPropertyNames && Object.defineProperty) {
|
||||
var props = Object.getOwnPropertyNames(obj), i;
|
||||
for (i = 0; i < props.length; i += 1) {
|
||||
Object.defineProperty(obj, props[i], {
|
||||
value: obj[props[i]],
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// emulate ES5 getter/setter API using legacy APIs
|
||||
// http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx
|
||||
if (Object.prototype.__defineGetter__ && !Object.defineProperty) {
|
||||
Object.defineProperty = function (obj, prop, desc) {
|
||||
if (desc.hasOwnProperty('get')) { obj.__defineGetter__(prop, desc.get); }
|
||||
if (desc.hasOwnProperty('set')) { obj.__defineSetter__(prop, desc.set); }
|
||||
};
|
||||
}
|
||||
|
||||
// ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value)
|
||||
// for index in 0 ... obj.length
|
||||
function makeArrayAccessors(obj) {
|
||||
if (!Object.defineProperty) { return; }
|
||||
|
||||
function makeArrayAccessor(index) {
|
||||
Object.defineProperty(obj, index, {
|
||||
'get': function () { return obj._getter(index); },
|
||||
'set': function (v) { obj._setter(index, v); },
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
|
||||
var i;
|
||||
for (i = 0; i < obj.length; i += 1) {
|
||||
makeArrayAccessor(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Internal conversion functions:
|
||||
// pack<Type>() - take a number (interpreted as Type), output a byte array
|
||||
// unpack<Type>() - take a byte array, output a Type-like number
|
||||
|
||||
function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; }
|
||||
function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; }
|
||||
|
||||
function packInt8(n) { return [n & 0xff]; }
|
||||
function unpackInt8(bytes) { return as_signed(bytes[0], 8); }
|
||||
|
||||
function packUint8(n) { return [n & 0xff]; }
|
||||
function unpackUint8(bytes) { return as_unsigned(bytes[0], 8); }
|
||||
|
||||
function packInt16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
||||
function unpackInt16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }
|
||||
|
||||
function packUint16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
|
||||
function unpackUint16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }
|
||||
|
||||
function packInt32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
||||
function unpackInt32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
||||
|
||||
function packUint32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
|
||||
function unpackUint32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
|
||||
|
||||
function packIEEE754(v, ebits, fbits) {
|
||||
|
||||
var bias = (1 << (ebits - 1)) - 1,
|
||||
s, e, f, ln,
|
||||
i, bits, str, bytes;
|
||||
|
||||
// Compute sign, exponent, fraction
|
||||
if (isNaN(v)) {
|
||||
// http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
|
||||
e = (1 << bias) - 1; f = Math.pow(2, fbits - 1); s = 0;
|
||||
}
|
||||
else if (v === Infinity || v === -Infinity) {
|
||||
e = (1 << bias) - 1; f = 0; s = (v < 0) ? 1 : 0;
|
||||
}
|
||||
else if (v === 0) {
|
||||
e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
|
||||
}
|
||||
else {
|
||||
s = v < 0;
|
||||
v = Math.abs(v);
|
||||
|
||||
if (v >= Math.pow(2, 1 - bias)) {
|
||||
// Normalized
|
||||
ln = Math.min(Math.floor(Math.log(v) / Math.LN2), bias);
|
||||
e = ln + bias;
|
||||
f = Math.round(v * Math.pow(2, fbits - ln) - Math.pow(2, fbits));
|
||||
}
|
||||
else {
|
||||
// Denormalized
|
||||
e = 0;
|
||||
f = Math.round(v / Math.pow(2, 1 - bias - fbits));
|
||||
}
|
||||
}
|
||||
|
||||
// Pack sign, exponent, fraction
|
||||
bits = [];
|
||||
for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = Math.floor(f / 2); }
|
||||
for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = Math.floor(e / 2); }
|
||||
bits.push(s ? 1 : 0);
|
||||
bits.reverse();
|
||||
str = bits.join('');
|
||||
|
||||
// Bits to bytes
|
||||
bytes = [];
|
||||
while (str.length) {
|
||||
bytes.push(parseInt(str.substring(0, 8), 2));
|
||||
str = str.substring(8);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
function unpackIEEE754(bytes, ebits, fbits) {
|
||||
|
||||
// Bytes to bits
|
||||
var bits = [], i, j, b, str,
|
||||
bias, s, e, f;
|
||||
|
||||
for (i = bytes.length; i; i -= 1) {
|
||||
b = bytes[i - 1];
|
||||
for (j = 8; j; j -= 1) {
|
||||
bits.push(b % 2 ? 1 : 0); b = b >> 1;
|
||||
}
|
||||
}
|
||||
bits.reverse();
|
||||
str = bits.join('');
|
||||
|
||||
// Unpack sign, exponent, fraction
|
||||
bias = (1 << (ebits - 1)) - 1;
|
||||
s = parseInt(str.substring(0, 1), 2) ? -1 : 1;
|
||||
e = parseInt(str.substring(1, 1 + ebits), 2);
|
||||
f = parseInt(str.substring(1 + ebits), 2);
|
||||
|
||||
// Produce number
|
||||
if (e === (1 << ebits) - 1) {
|
||||
return f !== 0 ? NaN : s * Infinity;
|
||||
}
|
||||
else if (e > 0) {
|
||||
// Normalized
|
||||
return s * Math.pow(2, e - bias) * (1 + f / Math.pow(2, fbits));
|
||||
}
|
||||
else if (f !== 0) {
|
||||
// Denormalized
|
||||
return s * Math.pow(2, -(bias - 1)) * (f / Math.pow(2, fbits));
|
||||
}
|
||||
else {
|
||||
return s < 0 ? -0 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
function unpackFloat64(b) { return unpackIEEE754(b, 11, 52); }
|
||||
function packFloat64(v) { return packIEEE754(v, 11, 52); }
|
||||
function unpackFloat32(b) { return unpackIEEE754(b, 8, 23); }
|
||||
function packFloat32(v) { return packIEEE754(v, 8, 23); }
|
||||
|
||||
|
||||
if (!ArrayBuffer) {
|
||||
(function () {
|
||||
|
||||
//
|
||||
// 3 The ArrayBuffer Type
|
||||
//
|
||||
|
||||
ArrayBuffer = function (length) {
|
||||
length = ECMAScript.ToInt32(length);
|
||||
if (length < 0) { throw new RangeError('ArrayBuffer size is not a small enough positive integer.'); }
|
||||
|
||||
this.byteLength = length;
|
||||
this._bytes = [];
|
||||
this._bytes.length = length;
|
||||
|
||||
var i;
|
||||
for (i = 0; i < this.byteLength; i += 1) {
|
||||
this._bytes[i] = 0;
|
||||
}
|
||||
|
||||
configureProperties(this);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// 4 The ArrayBufferView Type
|
||||
//
|
||||
|
||||
// NOTE: this constructor is not exported
|
||||
ArrayBufferView = function () {
|
||||
//this.buffer = null;
|
||||
//this.byteOffset = 0;
|
||||
//this.byteLength = 0;
|
||||
};
|
||||
|
||||
//
|
||||
// 5 The Typed Array View Types
|
||||
//
|
||||
|
||||
function makeTypedArrayConstructor(bytesPerElement, pack, unpack) {
|
||||
// Each TypedArray type requires a distinct constructor instance with
|
||||
// identical logic, which this produces.
|
||||
|
||||
var ctor;
|
||||
ctor = function (buffer, byteOffset, length) {
|
||||
var array, sequence, i, s;
|
||||
|
||||
// Constructor(unsigned long length)
|
||||
if (!arguments.length || typeof arguments[0] === 'number') {
|
||||
this.length = ECMAScript.ToInt32(arguments[0]);
|
||||
if (length < 0) { throw new RangeError('ArrayBufferView size is not a small enough positive integer.'); }
|
||||
|
||||
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
||||
this.buffer = new ArrayBuffer(this.byteLength);
|
||||
this.byteOffset = 0;
|
||||
}
|
||||
|
||||
// Constructor(TypedArray array)
|
||||
else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
|
||||
array = arguments[0];
|
||||
|
||||
this.length = array.length;
|
||||
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
||||
this.buffer = new ArrayBuffer(this.byteLength);
|
||||
this.byteOffset = 0;
|
||||
|
||||
for (i = 0; i < this.length; i += 1) {
|
||||
this._setter(i, array._getter(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor(sequence<type> array)
|
||||
else if (typeof arguments[0] === 'object' && !(arguments[0] instanceof ArrayBuffer)) {
|
||||
sequence = arguments[0];
|
||||
|
||||
this.length = ECMAScript.ToUint32(sequence.length);
|
||||
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
||||
this.buffer = new ArrayBuffer(this.byteLength);
|
||||
this.byteOffset = 0;
|
||||
|
||||
for (i = 0; i < this.length; i += 1) {
|
||||
s = sequence[i];
|
||||
this._setter(i, Number(s));
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor(ArrayBuffer buffer,
|
||||
// optional unsigned long byteOffset, optional unsigned long length)
|
||||
else if (typeof arguments[0] === 'object' && arguments[0] instanceof ArrayBuffer) {
|
||||
this.buffer = buffer;
|
||||
|
||||
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
||||
if (this.byteOffset > this.buffer.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // byteOffset out of range
|
||||
}
|
||||
|
||||
if (this.byteOffset % this.BYTES_PER_ELEMENT) {
|
||||
// The given byteOffset must be a multiple of the element
|
||||
// size of the specific type, otherwise an exception is raised.
|
||||
//raise_INDEX_SIZE_ERR();
|
||||
throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.");
|
||||
}
|
||||
|
||||
if (arguments.length < 3) {
|
||||
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
||||
|
||||
if (this.byteLength % this.BYTES_PER_ELEMENT) {
|
||||
raise_INDEX_SIZE_ERR(); // length of buffer minus byteOffset not a multiple of the element size
|
||||
}
|
||||
this.length = this.byteLength / this.BYTES_PER_ELEMENT;
|
||||
}
|
||||
else {
|
||||
this.length = ECMAScript.ToUint32(length);
|
||||
this.byteLength = this.length * this.BYTES_PER_ELEMENT;
|
||||
}
|
||||
|
||||
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // byteOffset and length reference an area beyond the end of the buffer
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new TypeError("Unexpected argument type(s)");
|
||||
}
|
||||
|
||||
this.constructor = ctor;
|
||||
|
||||
// ES5-only magic
|
||||
configureProperties(this);
|
||||
makeArrayAccessors(this);
|
||||
};
|
||||
|
||||
ctor.prototype = new ArrayBufferView();
|
||||
ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement;
|
||||
ctor.prototype._pack = pack;
|
||||
ctor.prototype._unpack = unpack;
|
||||
ctor.BYTES_PER_ELEMENT = bytesPerElement;
|
||||
|
||||
// getter type (unsigned long index);
|
||||
ctor.prototype._getter = function (index) {
|
||||
if (arguments.length < 1) { throw new SyntaxError("Not enough arguments"); }
|
||||
|
||||
index = ECMAScript.ToUint32(index);
|
||||
if (index >= this.length) {
|
||||
//raise_INDEX_SIZE_ERR(); // Array index out of range
|
||||
return; // undefined
|
||||
}
|
||||
|
||||
var bytes = [], i, o;
|
||||
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
||||
i < this.BYTES_PER_ELEMENT;
|
||||
i += 1, o += 1) {
|
||||
bytes.push(this.buffer._bytes[o]);
|
||||
}
|
||||
return this._unpack(bytes);
|
||||
};
|
||||
|
||||
// NONSTANDARD: convenience alias for getter: type get(unsigned long index);
|
||||
ctor.prototype.get = ctor.prototype._getter;
|
||||
|
||||
// setter void (unsigned long index, type value);
|
||||
ctor.prototype._setter = function (index, value) {
|
||||
if (arguments.length < 2) { throw new SyntaxError("Not enough arguments"); }
|
||||
|
||||
index = ECMAScript.ToUint32(index);
|
||||
if (index >= this.length) {
|
||||
//raise_INDEX_SIZE_ERR(); // Array index out of range
|
||||
return;
|
||||
}
|
||||
|
||||
var bytes = this._pack(value), i, o;
|
||||
for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
|
||||
i < this.BYTES_PER_ELEMENT;
|
||||
i += 1, o += 1) {
|
||||
this.buffer._bytes[o] = bytes[i];
|
||||
}
|
||||
};
|
||||
|
||||
// void set(TypedArray array, optional unsigned long offset);
|
||||
// void set(sequence<type> array, optional unsigned long offset);
|
||||
ctor.prototype.set = function (index, value) {
|
||||
if (arguments.length < 1) { throw new SyntaxError("Not enough arguments"); }
|
||||
var array, sequence, offset, len,
|
||||
i, s, d,
|
||||
byteOffset, byteLength, tmp;
|
||||
|
||||
// void set(TypedArray array, optional unsigned long offset);
|
||||
if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
|
||||
array = arguments[0];
|
||||
offset = ECMAScript.ToUint32(arguments[1]);
|
||||
|
||||
if (offset + array.length > this.length) {
|
||||
raise_INDEX_SIZE_ERR(); // Offset plus length of array is out of range
|
||||
}
|
||||
|
||||
byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT;
|
||||
byteLength = array.length * this.BYTES_PER_ELEMENT;
|
||||
|
||||
if (array.buffer === this.buffer) {
|
||||
tmp = [];
|
||||
for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) {
|
||||
tmp[i] = array.buffer._bytes[s];
|
||||
}
|
||||
for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) {
|
||||
this.buffer._bytes[d] = tmp[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i = 0, s = array.byteOffset, d = byteOffset;
|
||||
i < byteLength; i += 1, s += 1, d += 1) {
|
||||
this.buffer._bytes[d] = array.buffer._bytes[s];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void set(sequence<type> array, optional unsigned long offset);
|
||||
else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
|
||||
sequence = arguments[0];
|
||||
len = ECMAScript.ToUint32(sequence.length);
|
||||
offset = ECMAScript.ToUint32(arguments[1]);
|
||||
|
||||
if (offset + len > this.length) {
|
||||
raise_INDEX_SIZE_ERR(); // Offset plus length of array is out of range
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
s = sequence[i];
|
||||
this._setter(offset + i, Number(s));
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
throw new TypeError("Unexpected argument type(s)");
|
||||
}
|
||||
};
|
||||
|
||||
// TypedArray subarray(long begin, optional long end);
|
||||
ctor.prototype.subarray = function (start, end) {
|
||||
function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
|
||||
|
||||
start = ECMAScript.ToInt32(start);
|
||||
end = ECMAScript.ToInt32(end);
|
||||
|
||||
if (arguments.length < 1) { start = 0; }
|
||||
if (arguments.length < 2) { end = this.length; }
|
||||
|
||||
if (start < 0) { start = this.length + start; }
|
||||
if (end < 0) { end = this.length + end; }
|
||||
|
||||
start = clamp(start, 0, this.length);
|
||||
end = clamp(end, 0, this.length);
|
||||
|
||||
var len = end - start;
|
||||
if (len < 0) {
|
||||
len = 0;
|
||||
}
|
||||
|
||||
return new this.constructor(this.buffer, start * this.BYTES_PER_ELEMENT, len);
|
||||
};
|
||||
|
||||
return ctor;
|
||||
}
|
||||
|
||||
Int8Array = Int8Array || makeTypedArrayConstructor(1, packInt8, unpackInt8);
|
||||
Uint8Array = Uint8Array || makeTypedArrayConstructor(1, packUint8, unpackUint8);
|
||||
Int16Array = Int16Array || makeTypedArrayConstructor(2, packInt16, unpackInt16);
|
||||
Uint16Array = Uint16Array || makeTypedArrayConstructor(2, packUint16, unpackUint16);
|
||||
Int32Array = Int32Array || makeTypedArrayConstructor(4, packInt32, unpackInt32);
|
||||
Uint32Array = Uint32Array || makeTypedArrayConstructor(4, packUint32, unpackUint32);
|
||||
Float32Array = Float32Array || makeTypedArrayConstructor(4, packFloat32, unpackFloat32);
|
||||
Float64Array = Float64Array || makeTypedArrayConstructor(8, packFloat64, unpackFloat64);
|
||||
|
||||
} ());
|
||||
}
|
||||
|
||||
|
||||
if (!DataView) {
|
||||
(function () {
|
||||
|
||||
//
|
||||
// 6 The DataView View Type
|
||||
//
|
||||
|
||||
function r(array, index) {
|
||||
if (typeof array.get === 'function') {
|
||||
return array.get(index);
|
||||
}
|
||||
else {
|
||||
return array[index];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var IS_BIG_ENDIAN = (function () {
|
||||
var u16array = new Uint16Array([0x1234]),
|
||||
u8array = new Uint8Array(u16array.buffer);
|
||||
return r(u8array, 0) === 0x12;
|
||||
} ());
|
||||
|
||||
// Constructor(ArrayBuffer buffer,
|
||||
// optional unsigned long byteOffset,
|
||||
// optional unsigned long byteLength)
|
||||
DataView = function (buffer, byteOffset, byteLength) {
|
||||
if (!(typeof buffer === 'object' && buffer instanceof ArrayBuffer)) {
|
||||
throw new TypeError("TypeError");
|
||||
}
|
||||
|
||||
this.buffer = buffer;
|
||||
|
||||
this.byteOffset = ECMAScript.ToUint32(byteOffset);
|
||||
if (this.byteOffset > this.buffer.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // byteOffset out of range
|
||||
}
|
||||
|
||||
if (arguments.length < 3) {
|
||||
this.byteLength = this.buffer.byteLength - this.byteOffset;
|
||||
}
|
||||
else {
|
||||
this.byteLength = ECMAScript.ToUint32(byteLength);
|
||||
}
|
||||
|
||||
if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // byteOffset and length reference an area beyond the end of the buffer
|
||||
}
|
||||
|
||||
// ES5-only magic
|
||||
configureProperties(this);
|
||||
};
|
||||
|
||||
if (ArrayBufferView) {
|
||||
DataView.prototype = new ArrayBufferView();
|
||||
}
|
||||
|
||||
function makeDataView_getter(arrayType) {
|
||||
return function (byteOffset, littleEndian) {
|
||||
/*jslint newcap: false*/
|
||||
byteOffset = ECMAScript.ToUint32(byteOffset);
|
||||
|
||||
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // Array index out of range
|
||||
}
|
||||
byteOffset += this.byteOffset;
|
||||
|
||||
var uint8Array = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT),
|
||||
bytes = [], i;
|
||||
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
||||
bytes.push(r(uint8Array, i));
|
||||
}
|
||||
|
||||
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
||||
bytes.reverse();
|
||||
}
|
||||
|
||||
return r(new arrayType(new Uint8Array(bytes).buffer), 0);
|
||||
};
|
||||
}
|
||||
|
||||
DataView.prototype.getUint8 = makeDataView_getter(Uint8Array);
|
||||
DataView.prototype.getInt8 = makeDataView_getter(Int8Array);
|
||||
DataView.prototype.getUint16 = makeDataView_getter(Uint16Array);
|
||||
DataView.prototype.getInt16 = makeDataView_getter(Int16Array);
|
||||
DataView.prototype.getUint32 = makeDataView_getter(Uint32Array);
|
||||
DataView.prototype.getInt32 = makeDataView_getter(Int32Array);
|
||||
DataView.prototype.getFloat32 = makeDataView_getter(Float32Array);
|
||||
DataView.prototype.getFloat64 = makeDataView_getter(Float64Array);
|
||||
|
||||
function makeDataView_setter(arrayType) {
|
||||
return function (byteOffset, value, littleEndian) {
|
||||
/*jslint newcap: false*/
|
||||
byteOffset = ECMAScript.ToUint32(byteOffset);
|
||||
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
|
||||
raise_INDEX_SIZE_ERR(); // Array index out of range
|
||||
}
|
||||
|
||||
// Get bytes
|
||||
var typeArray = new arrayType([value]),
|
||||
byteArray = new Uint8Array(typeArray.buffer),
|
||||
bytes = [], i, byteView;
|
||||
|
||||
for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
|
||||
bytes.push(r(byteArray, i));
|
||||
}
|
||||
|
||||
// Flip if necessary
|
||||
if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
|
||||
bytes.reverse();
|
||||
}
|
||||
|
||||
// Write them
|
||||
byteView = new Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT);
|
||||
byteView.set(bytes);
|
||||
};
|
||||
}
|
||||
|
||||
DataView.prototype.setUint8 = makeDataView_setter(Uint8Array);
|
||||
DataView.prototype.setInt8 = makeDataView_setter(Int8Array);
|
||||
DataView.prototype.setUint16 = makeDataView_setter(Uint16Array);
|
||||
DataView.prototype.setInt16 = makeDataView_setter(Int16Array);
|
||||
DataView.prototype.setUint32 = makeDataView_setter(Uint32Array);
|
||||
DataView.prototype.setInt32 = makeDataView_setter(Int32Array);
|
||||
DataView.prototype.setFloat32 = makeDataView_setter(Float32Array);
|
||||
DataView.prototype.setFloat64 = makeDataView_setter(Float64Array);
|
||||
|
||||
} ());
|
||||
}
|
||||
|
||||
} ());
|
||||
|
1
files_reader/js/libs/typedarray.min.js
vendored
Normal file
1
files_reader/js/libs/typedarray.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
241
files_reader/js/libs/zip-ext.js
Normal file
241
files_reader/js/libs/zip-ext.js
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var ERR_HTTP_RANGE = "HTTP Range not supported.";
|
||||
|
||||
var Reader = zip.Reader;
|
||||
var Writer = zip.Writer;
|
||||
|
||||
var ZipDirectoryEntry;
|
||||
|
||||
var appendABViewSupported;
|
||||
try {
|
||||
appendABViewSupported = new Blob([ new DataView(new ArrayBuffer(0)) ]).size === 0;
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
function HttpReader(url) {
|
||||
var that = this;
|
||||
|
||||
function getData(callback, onerror) {
|
||||
var request;
|
||||
if (!that.data) {
|
||||
request = new XMLHttpRequest();
|
||||
request.addEventListener("load", function() {
|
||||
if (!that.size)
|
||||
that.size = Number(request.getResponseHeader("Content-Length"));
|
||||
that.data = new Uint8Array(request.response);
|
||||
callback();
|
||||
}, false);
|
||||
request.addEventListener("error", onerror, false);
|
||||
request.open("GET", url);
|
||||
request.responseType = "arraybuffer";
|
||||
request.send();
|
||||
} else
|
||||
callback();
|
||||
}
|
||||
|
||||
function init(callback, onerror) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.addEventListener("load", function() {
|
||||
that.size = Number(request.getResponseHeader("Content-Length"));
|
||||
callback();
|
||||
}, false);
|
||||
request.addEventListener("error", onerror, false);
|
||||
request.open("HEAD", url);
|
||||
request.send();
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
getData(function() {
|
||||
callback(new Uint8Array(that.data.subarray(index, index + length)));
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
HttpReader.prototype = new Reader();
|
||||
HttpReader.prototype.constructor = HttpReader;
|
||||
|
||||
function HttpRangeReader(url) {
|
||||
var that = this;
|
||||
|
||||
function init(callback, onerror) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.addEventListener("load", function() {
|
||||
that.size = Number(request.getResponseHeader("Content-Length"));
|
||||
if (request.getResponseHeader("Accept-Ranges") == "bytes")
|
||||
callback();
|
||||
else
|
||||
onerror(ERR_HTTP_RANGE);
|
||||
}, false);
|
||||
request.addEventListener("error", onerror, false);
|
||||
request.open("HEAD", url);
|
||||
request.send();
|
||||
}
|
||||
|
||||
function readArrayBuffer(index, length, callback, onerror) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.open("GET", url);
|
||||
request.responseType = "arraybuffer";
|
||||
request.setRequestHeader("Range", "bytes=" + index + "-" + (index + length - 1));
|
||||
request.addEventListener("load", function() {
|
||||
callback(request.response);
|
||||
}, false);
|
||||
request.addEventListener("error", onerror, false);
|
||||
request.send();
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
readArrayBuffer(index, length, function(arraybuffer) {
|
||||
callback(new Uint8Array(arraybuffer));
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
HttpRangeReader.prototype = new Reader();
|
||||
HttpRangeReader.prototype.constructor = HttpRangeReader;
|
||||
|
||||
function ArrayBufferReader(arrayBuffer) {
|
||||
var that = this;
|
||||
|
||||
function init(callback, onerror) {
|
||||
that.size = arrayBuffer.byteLength;
|
||||
callback();
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
callback(new Uint8Array(arrayBuffer.slice(index, index + length)));
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
ArrayBufferReader.prototype = new Reader();
|
||||
ArrayBufferReader.prototype.constructor = ArrayBufferReader;
|
||||
|
||||
function ArrayBufferWriter() {
|
||||
var array, that = this;
|
||||
|
||||
function init(callback, onerror) {
|
||||
array = new Uint8Array();
|
||||
callback();
|
||||
}
|
||||
|
||||
function writeUint8Array(arr, callback, onerror) {
|
||||
var tmpArray = new Uint8Array(array.length + arr.length);
|
||||
tmpArray.set(array);
|
||||
tmpArray.set(arr, array.length);
|
||||
array = tmpArray;
|
||||
callback();
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
callback(array.buffer);
|
||||
}
|
||||
|
||||
that.init = init;
|
||||
that.writeUint8Array = writeUint8Array;
|
||||
that.getData = getData;
|
||||
}
|
||||
ArrayBufferWriter.prototype = new Writer();
|
||||
ArrayBufferWriter.prototype.constructor = ArrayBufferWriter;
|
||||
|
||||
function FileWriter(fileEntry, contentType) {
|
||||
var writer, that = this;
|
||||
|
||||
function init(callback, onerror) {
|
||||
fileEntry.createWriter(function(fileWriter) {
|
||||
writer = fileWriter;
|
||||
callback();
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function writeUint8Array(array, callback, onerror) {
|
||||
var blob = new Blob([ appendABViewSupported ? array : array.buffer ], {
|
||||
type : contentType
|
||||
});
|
||||
writer.onwrite = function() {
|
||||
writer.onwrite = null;
|
||||
callback();
|
||||
};
|
||||
writer.onerror = onerror;
|
||||
writer.write(blob);
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
fileEntry.file(callback);
|
||||
}
|
||||
|
||||
that.init = init;
|
||||
that.writeUint8Array = writeUint8Array;
|
||||
that.getData = getData;
|
||||
}
|
||||
FileWriter.prototype = new Writer();
|
||||
FileWriter.prototype.constructor = FileWriter;
|
||||
|
||||
zip.FileWriter = FileWriter;
|
||||
zip.HttpReader = HttpReader;
|
||||
zip.HttpRangeReader = HttpRangeReader;
|
||||
zip.ArrayBufferReader = ArrayBufferReader;
|
||||
zip.ArrayBufferWriter = ArrayBufferWriter;
|
||||
|
||||
if (zip.fs) {
|
||||
ZipDirectoryEntry = zip.fs.ZipDirectoryEntry;
|
||||
ZipDirectoryEntry.prototype.addHttpContent = function(name, URL, useRangeHeader) {
|
||||
function addChild(parent, name, params, directory) {
|
||||
if (parent.directory)
|
||||
return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new zip.fs.ZipFileEntry(parent.fs, name, params, parent);
|
||||
else
|
||||
throw "Parent entry is not a directory.";
|
||||
}
|
||||
|
||||
return addChild(this, name, {
|
||||
data : URL,
|
||||
Reader : useRangeHeader ? HttpRangeReader : HttpReader
|
||||
});
|
||||
};
|
||||
ZipDirectoryEntry.prototype.importHttpContent = function(URL, useRangeHeader, onend, onerror) {
|
||||
this.importZip(useRangeHeader ? new HttpRangeReader(URL) : new HttpReader(URL), onend, onerror);
|
||||
};
|
||||
zip.fs.FS.prototype.importHttpContent = function(URL, useRangeHeader, onend, onerror) {
|
||||
this.entries = [];
|
||||
this.root = new ZipDirectoryEntry(this);
|
||||
this.root.importHttpContent(URL, useRangeHeader, onend, onerror);
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
538
files_reader/js/libs/zip-fs.js
Normal file
538
files_reader/js/libs/zip-fs.js
Normal file
|
@ -0,0 +1,538 @@
|
|||
/*
|
||||
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var CHUNK_SIZE = 512 * 1024;
|
||||
|
||||
var TextWriter = zip.TextWriter, //
|
||||
BlobWriter = zip.BlobWriter, //
|
||||
Data64URIWriter = zip.Data64URIWriter, //
|
||||
Reader = zip.Reader, //
|
||||
TextReader = zip.TextReader, //
|
||||
BlobReader = zip.BlobReader, //
|
||||
Data64URIReader = zip.Data64URIReader, //
|
||||
createReader = zip.createReader, //
|
||||
createWriter = zip.createWriter;
|
||||
|
||||
function ZipBlobReader(entry) {
|
||||
var that = this, blobReader;
|
||||
|
||||
function init(callback) {
|
||||
this.size = entry.uncompressedSize;
|
||||
callback();
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
if (that.data)
|
||||
callback();
|
||||
else
|
||||
entry.getData(new BlobWriter(), function(data) {
|
||||
that.data = data;
|
||||
blobReader = new BlobReader(data);
|
||||
callback();
|
||||
}, null, that.checkCrc32);
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
getData(function() {
|
||||
blobReader.readUint8Array(index, length, callback, onerror);
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
ZipBlobReader.prototype = new Reader();
|
||||
ZipBlobReader.prototype.constructor = ZipBlobReader;
|
||||
ZipBlobReader.prototype.checkCrc32 = false;
|
||||
|
||||
function getTotalSize(entry) {
|
||||
var size = 0;
|
||||
|
||||
function process(entry) {
|
||||
size += entry.uncompressedSize || 0;
|
||||
entry.children.forEach(process);
|
||||
}
|
||||
|
||||
process(entry);
|
||||
return size;
|
||||
}
|
||||
|
||||
function initReaders(entry, onend, onerror) {
|
||||
var index = 0;
|
||||
|
||||
function next() {
|
||||
index++;
|
||||
if (index < entry.children.length)
|
||||
process(entry.children[index]);
|
||||
else
|
||||
onend();
|
||||
}
|
||||
|
||||
function process(child) {
|
||||
if (child.directory)
|
||||
initReaders(child, next, onerror);
|
||||
else {
|
||||
child.reader = new child.Reader(child.data, onerror);
|
||||
child.reader.init(function() {
|
||||
child.uncompressedSize = child.reader.size;
|
||||
next();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.children.length)
|
||||
process(entry.children[index]);
|
||||
else
|
||||
onend();
|
||||
}
|
||||
|
||||
function detach(entry) {
|
||||
var children = entry.parent.children;
|
||||
children.forEach(function(child, index) {
|
||||
if (child.id == entry.id)
|
||||
children.splice(index, 1);
|
||||
});
|
||||
}
|
||||
|
||||
function exportZip(zipWriter, entry, onend, onprogress, totalSize) {
|
||||
var currentIndex = 0;
|
||||
|
||||
function process(zipWriter, entry, onend, onprogress, totalSize) {
|
||||
var childIndex = 0;
|
||||
|
||||
function exportChild() {
|
||||
var child = entry.children[childIndex];
|
||||
if (child)
|
||||
zipWriter.add(child.getFullname(), child.reader, function() {
|
||||
currentIndex += child.uncompressedSize || 0;
|
||||
process(zipWriter, child, function() {
|
||||
childIndex++;
|
||||
exportChild();
|
||||
}, onprogress, totalSize);
|
||||
}, function(index) {
|
||||
if (onprogress)
|
||||
onprogress(currentIndex + index, totalSize);
|
||||
}, {
|
||||
directory : child.directory,
|
||||
version : child.zipVersion
|
||||
});
|
||||
else
|
||||
onend();
|
||||
}
|
||||
|
||||
exportChild();
|
||||
}
|
||||
|
||||
process(zipWriter, entry, onend, onprogress, totalSize);
|
||||
}
|
||||
|
||||
function addFileEntry(zipEntry, fileEntry, onend, onerror) {
|
||||
function getChildren(fileEntry, callback) {
|
||||
if (fileEntry.isDirectory)
|
||||
fileEntry.createReader().readEntries(callback);
|
||||
if (fileEntry.isFile)
|
||||
callback([]);
|
||||
}
|
||||
|
||||
function process(zipEntry, fileEntry, onend) {
|
||||
getChildren(fileEntry, function(children) {
|
||||
var childIndex = 0;
|
||||
|
||||
function addChild(child) {
|
||||
function nextChild(childFileEntry) {
|
||||
process(childFileEntry, child, function() {
|
||||
childIndex++;
|
||||
processChild();
|
||||
});
|
||||
}
|
||||
|
||||
if (child.isDirectory)
|
||||
nextChild(zipEntry.addDirectory(child.name));
|
||||
if (child.isFile)
|
||||
child.file(function(file) {
|
||||
var childZipEntry = zipEntry.addBlob(child.name, file);
|
||||
childZipEntry.uncompressedSize = file.size;
|
||||
nextChild(childZipEntry);
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function processChild() {
|
||||
var child = children[childIndex];
|
||||
if (child)
|
||||
addChild(child);
|
||||
else
|
||||
onend();
|
||||
}
|
||||
|
||||
processChild();
|
||||
});
|
||||
}
|
||||
|
||||
if (fileEntry.isDirectory)
|
||||
process(zipEntry, fileEntry, onend);
|
||||
else
|
||||
fileEntry.file(function(file) {
|
||||
zipEntry.addBlob(fileEntry.name, file);
|
||||
onend();
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function getFileEntry(fileEntry, entry, onend, onprogress, onerror, totalSize, checkCrc32) {
|
||||
var currentIndex = 0;
|
||||
|
||||
function process(fileEntry, entry, onend, onprogress, onerror, totalSize) {
|
||||
var childIndex = 0;
|
||||
|
||||
function addChild(child) {
|
||||
function nextChild(childFileEntry) {
|
||||
currentIndex += child.uncompressedSize || 0;
|
||||
process(childFileEntry, child, function() {
|
||||
childIndex++;
|
||||
processChild();
|
||||
}, onprogress, onerror, totalSize);
|
||||
}
|
||||
|
||||
if (child.directory)
|
||||
fileEntry.getDirectory(child.name, {
|
||||
create : true
|
||||
}, nextChild, onerror);
|
||||
else
|
||||
fileEntry.getFile(child.name, {
|
||||
create : true
|
||||
}, function(file) {
|
||||
child.getData(new zip.FileWriter(file, zip.getMimeType(child.name)), nextChild, function(index) {
|
||||
if (onprogress)
|
||||
onprogress(currentIndex + index, totalSize);
|
||||
}, checkCrc32);
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function processChild() {
|
||||
var child = entry.children[childIndex];
|
||||
if (child)
|
||||
addChild(child);
|
||||
else
|
||||
onend();
|
||||
}
|
||||
|
||||
processChild();
|
||||
}
|
||||
|
||||
if (entry.directory)
|
||||
process(fileEntry, entry, onend, onprogress, onerror, totalSize);
|
||||
else
|
||||
entry.getData(new zip.FileWriter(fileEntry, zip.getMimeType(entry.name)), onend, onprogress, checkCrc32);
|
||||
}
|
||||
|
||||
function resetFS(fs) {
|
||||
fs.entries = [];
|
||||
fs.root = new ZipDirectoryEntry(fs);
|
||||
}
|
||||
|
||||
function bufferedCopy(reader, writer, onend, onprogress, onerror) {
|
||||
var chunkIndex = 0;
|
||||
|
||||
function stepCopy() {
|
||||
var index = chunkIndex * CHUNK_SIZE;
|
||||
if (onprogress)
|
||||
onprogress(index, reader.size);
|
||||
if (index < reader.size)
|
||||
reader.readUint8Array(index, Math.min(CHUNK_SIZE, reader.size - index), function(array) {
|
||||
writer.writeUint8Array(new Uint8Array(array), function() {
|
||||
chunkIndex++;
|
||||
stepCopy();
|
||||
});
|
||||
}, onerror);
|
||||
else
|
||||
writer.getData(onend);
|
||||
}
|
||||
|
||||
stepCopy();
|
||||
}
|
||||
|
||||
function getEntryData(writer, onend, onprogress, onerror) {
|
||||
var that = this;
|
||||
if (!writer || (writer.constructor == that.Writer && that.data))
|
||||
onend(that.data);
|
||||
else {
|
||||
if (!that.reader)
|
||||
that.reader = new that.Reader(that.data, onerror);
|
||||
that.reader.init(function() {
|
||||
writer.init(function() {
|
||||
bufferedCopy(that.reader, writer, onend, onprogress, onerror);
|
||||
}, onerror);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function addChild(parent, name, params, directory) {
|
||||
if (parent.directory)
|
||||
return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
|
||||
else
|
||||
throw "Parent entry is not a directory.";
|
||||
}
|
||||
|
||||
function ZipEntry() {
|
||||
}
|
||||
|
||||
ZipEntry.prototype = {
|
||||
init : function(fs, name, params, parent) {
|
||||
var that = this;
|
||||
if (fs.root && parent && parent.getChildByName(name))
|
||||
throw "Entry filename already exists.";
|
||||
if (!params)
|
||||
params = {};
|
||||
that.fs = fs;
|
||||
that.name = name;
|
||||
that.id = fs.entries.length;
|
||||
that.parent = parent;
|
||||
that.children = [];
|
||||
that.zipVersion = params.zipVersion || 0x14;
|
||||
that.uncompressedSize = 0;
|
||||
fs.entries.push(that);
|
||||
if (parent)
|
||||
that.parent.children.push(that);
|
||||
},
|
||||
getFileEntry : function(fileEntry, onend, onprogress, onerror, checkCrc32) {
|
||||
var that = this;
|
||||
initReaders(that, function() {
|
||||
getFileEntry(fileEntry, that, onend, onprogress, onerror, getTotalSize(that), checkCrc32);
|
||||
}, onerror);
|
||||
},
|
||||
moveTo : function(target) {
|
||||
var that = this;
|
||||
if (target.directory) {
|
||||
if (!target.isDescendantOf(that)) {
|
||||
if (that != target) {
|
||||
if (target.getChildByName(that.name))
|
||||
throw "Entry filename already exists.";
|
||||
detach(that);
|
||||
that.parent = target;
|
||||
target.children.push(that);
|
||||
}
|
||||
} else
|
||||
throw "Entry is a ancestor of target entry.";
|
||||
} else
|
||||
throw "Target entry is not a directory.";
|
||||
},
|
||||
getFullname : function() {
|
||||
var that = this, fullname = that.name, entry = that.parent;
|
||||
while (entry) {
|
||||
fullname = (entry.name ? entry.name + "/" : "") + fullname;
|
||||
entry = entry.parent;
|
||||
}
|
||||
return fullname;
|
||||
},
|
||||
isDescendantOf : function(ancestor) {
|
||||
var entry = this.parent;
|
||||
while (entry && entry.id != ancestor.id)
|
||||
entry = entry.parent;
|
||||
return !!entry;
|
||||
}
|
||||
};
|
||||
ZipEntry.prototype.constructor = ZipEntry;
|
||||
|
||||
var ZipFileEntryProto;
|
||||
|
||||
function ZipFileEntry(fs, name, params, parent) {
|
||||
var that = this;
|
||||
ZipEntry.prototype.init.call(that, fs, name, params, parent);
|
||||
that.Reader = params.Reader;
|
||||
that.Writer = params.Writer;
|
||||
that.data = params.data;
|
||||
that.getData = params.getData || getEntryData;
|
||||
}
|
||||
|
||||
ZipFileEntry.prototype = ZipFileEntryProto = new ZipEntry();
|
||||
ZipFileEntryProto.constructor = ZipFileEntry;
|
||||
ZipFileEntryProto.getText = function(onend, onprogress, checkCrc32, encoding) {
|
||||
this.getData(new TextWriter(encoding), onend, onprogress, checkCrc32);
|
||||
};
|
||||
ZipFileEntryProto.getBlob = function(mimeType, onend, onprogress, checkCrc32) {
|
||||
this.getData(new BlobWriter(mimeType), onend, onprogress, checkCrc32);
|
||||
};
|
||||
ZipFileEntryProto.getData64URI = function(mimeType, onend, onprogress, checkCrc32) {
|
||||
this.getData(new Data64URIWriter(mimeType), onend, onprogress, checkCrc32);
|
||||
};
|
||||
|
||||
var ZipDirectoryEntryProto;
|
||||
|
||||
function ZipDirectoryEntry(fs, name, params, parent) {
|
||||
var that = this;
|
||||
ZipEntry.prototype.init.call(that, fs, name, params, parent);
|
||||
that.directory = true;
|
||||
}
|
||||
|
||||
ZipDirectoryEntry.prototype = ZipDirectoryEntryProto = new ZipEntry();
|
||||
ZipDirectoryEntryProto.constructor = ZipDirectoryEntry;
|
||||
ZipDirectoryEntryProto.addDirectory = function(name) {
|
||||
return addChild(this, name, null, true);
|
||||
};
|
||||
ZipDirectoryEntryProto.addText = function(name, text) {
|
||||
return addChild(this, name, {
|
||||
data : text,
|
||||
Reader : TextReader,
|
||||
Writer : TextWriter
|
||||
});
|
||||
};
|
||||
ZipDirectoryEntryProto.addBlob = function(name, blob) {
|
||||
return addChild(this, name, {
|
||||
data : blob,
|
||||
Reader : BlobReader,
|
||||
Writer : BlobWriter
|
||||
});
|
||||
};
|
||||
ZipDirectoryEntryProto.addData64URI = function(name, dataURI) {
|
||||
return addChild(this, name, {
|
||||
data : dataURI,
|
||||
Reader : Data64URIReader,
|
||||
Writer : Data64URIWriter
|
||||
});
|
||||
};
|
||||
ZipDirectoryEntryProto.addFileEntry = function(fileEntry, onend, onerror) {
|
||||
addFileEntry(this, fileEntry, onend, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.addData = function(name, params) {
|
||||
return addChild(this, name, params);
|
||||
};
|
||||
ZipDirectoryEntryProto.importBlob = function(blob, onend, onerror) {
|
||||
this.importZip(new BlobReader(blob), onend, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.importText = function(text, onend, onerror) {
|
||||
this.importZip(new TextReader(text), onend, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.importData64URI = function(dataURI, onend, onerror) {
|
||||
this.importZip(new Data64URIReader(dataURI), onend, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.exportBlob = function(onend, onprogress, onerror) {
|
||||
this.exportZip(new BlobWriter("application/zip"), onend, onprogress, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.exportText = function(onend, onprogress, onerror) {
|
||||
this.exportZip(new TextWriter(), onend, onprogress, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.exportFileEntry = function(fileEntry, onend, onprogress, onerror) {
|
||||
this.exportZip(new zip.FileWriter(fileEntry, "application/zip"), onend, onprogress, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.exportData64URI = function(onend, onprogress, onerror) {
|
||||
this.exportZip(new Data64URIWriter("application/zip"), onend, onprogress, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.importZip = function(reader, onend, onerror) {
|
||||
var that = this;
|
||||
createReader(reader, function(zipReader) {
|
||||
zipReader.getEntries(function(entries) {
|
||||
entries.forEach(function(entry) {
|
||||
var parent = that, path = entry.filename.split("/"), name = path.pop();
|
||||
path.forEach(function(pathPart) {
|
||||
parent = parent.getChildByName(pathPart) || new ZipDirectoryEntry(that.fs, pathPart, null, parent);
|
||||
});
|
||||
if (!entry.directory)
|
||||
addChild(parent, name, {
|
||||
data : entry,
|
||||
Reader : ZipBlobReader
|
||||
});
|
||||
});
|
||||
onend();
|
||||
});
|
||||
}, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.exportZip = function(writer, onend, onprogress, onerror) {
|
||||
var that = this;
|
||||
initReaders(that, function() {
|
||||
createWriter(writer, function(zipWriter) {
|
||||
exportZip(zipWriter, that, function() {
|
||||
zipWriter.close(onend);
|
||||
}, onprogress, getTotalSize(that));
|
||||
}, onerror);
|
||||
}, onerror);
|
||||
};
|
||||
ZipDirectoryEntryProto.getChildByName = function(name) {
|
||||
var childIndex, child, that = this;
|
||||
for (childIndex = 0; childIndex < that.children.length; childIndex++) {
|
||||
child = that.children[childIndex];
|
||||
if (child.name == name)
|
||||
return child;
|
||||
}
|
||||
};
|
||||
|
||||
function FS() {
|
||||
resetFS(this);
|
||||
}
|
||||
FS.prototype = {
|
||||
remove : function(entry) {
|
||||
detach(entry);
|
||||
this.entries[entry.id] = null;
|
||||
},
|
||||
find : function(fullname) {
|
||||
var index, path = fullname.split("/"), node = this.root;
|
||||
for (index = 0; node && index < path.length; index++)
|
||||
node = node.getChildByName(path[index]);
|
||||
return node;
|
||||
},
|
||||
getById : function(id) {
|
||||
return this.entries[id];
|
||||
},
|
||||
importBlob : function(blob, onend, onerror) {
|
||||
resetFS(this);
|
||||
this.root.importBlob(blob, onend, onerror);
|
||||
},
|
||||
importText : function(text, onend, onerror) {
|
||||
resetFS(this);
|
||||
this.root.importText(text, onend, onerror);
|
||||
},
|
||||
importData64URI : function(dataURI, onend, onerror) {
|
||||
resetFS(this);
|
||||
this.root.importData64URI(dataURI, onend, onerror);
|
||||
},
|
||||
exportBlob : function(onend, onprogress, onerror) {
|
||||
this.root.exportBlob(onend, onprogress, onerror);
|
||||
},
|
||||
exportText : function(onend, onprogress, onerror) {
|
||||
this.root.exportText(onend, onprogress, onerror);
|
||||
},
|
||||
exportFileEntry : function(fileEntry, onend, onprogress, onerror) {
|
||||
this.root.exportFileEntry(fileEntry, onend, onprogress, onerror);
|
||||
},
|
||||
exportData64URI : function(onend, onprogress, onerror) {
|
||||
this.root.exportData64URI(onend, onprogress, onerror);
|
||||
}
|
||||
};
|
||||
|
||||
zip.fs = {
|
||||
FS : FS,
|
||||
ZipDirectoryEntry : ZipDirectoryEntry,
|
||||
ZipFileEntry : ZipFileEntry
|
||||
};
|
||||
|
||||
zip.getMimeType = function() {
|
||||
return "application/octet-stream";
|
||||
};
|
||||
|
||||
})();
|
801
files_reader/js/libs/zip.js
Normal file
801
files_reader/js/libs/zip.js
Normal file
|
@ -0,0 +1,801 @@
|
|||
/*
|
||||
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of the authors may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
(function(obj) {
|
||||
|
||||
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).";
|
||||
var ERR_READ = "Error while reading zip file.";
|
||||
var ERR_WRITE = "Error while writing zip file.";
|
||||
var ERR_WRITE_DATA = "Error while writing file data.";
|
||||
var ERR_READ_DATA = "Error while reading file data.";
|
||||
var ERR_DUPLICATED_NAME = "File already exists.";
|
||||
var CHUNK_SIZE = 512 * 1024;
|
||||
|
||||
var INFLATE_JS = "inflate.js";
|
||||
var DEFLATE_JS = "deflate.js";
|
||||
|
||||
var TEXT_PLAIN = "text/plain";
|
||||
|
||||
var MESSAGE_EVENT = "message";
|
||||
|
||||
var appendABViewSupported;
|
||||
try {
|
||||
appendABViewSupported = new Blob([ new DataView(new ArrayBuffer(0)) ]).size === 0;
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
function Crc32() {
|
||||
var crc = -1, that = this;
|
||||
that.append = function(data) {
|
||||
var offset, table = that.table;
|
||||
for (offset = 0; offset < data.length; offset++)
|
||||
crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
|
||||
};
|
||||
that.get = function() {
|
||||
return ~crc;
|
||||
};
|
||||
}
|
||||
Crc32.prototype.table = (function() {
|
||||
var i, j, t, table = [];
|
||||
for (i = 0; i < 256; i++) {
|
||||
t = i;
|
||||
for (j = 0; j < 8; j++)
|
||||
if (t & 1)
|
||||
t = (t >>> 1) ^ 0xEDB88320;
|
||||
else
|
||||
t = t >>> 1;
|
||||
table[i] = t;
|
||||
}
|
||||
return table;
|
||||
})();
|
||||
|
||||
function blobSlice(blob, index, length) {
|
||||
if (blob.slice)
|
||||
return blob.slice(index, index + length);
|
||||
else if (blob.webkitSlice)
|
||||
return blob.webkitSlice(index, index + length);
|
||||
else if (blob.mozSlice)
|
||||
return blob.mozSlice(index, index + length);
|
||||
else if (blob.msSlice)
|
||||
return blob.msSlice(index, index + length);
|
||||
}
|
||||
|
||||
function getDataHelper(byteLength, bytes) {
|
||||
var dataBuffer, dataArray;
|
||||
dataBuffer = new ArrayBuffer(byteLength);
|
||||
dataArray = new Uint8Array(dataBuffer);
|
||||
if (bytes)
|
||||
dataArray.set(bytes, 0);
|
||||
return {
|
||||
buffer : dataBuffer,
|
||||
array : dataArray,
|
||||
view : new DataView(dataBuffer)
|
||||
};
|
||||
}
|
||||
|
||||
// Readers
|
||||
function Reader() {
|
||||
}
|
||||
|
||||
function TextReader(text) {
|
||||
var that = this, blobReader;
|
||||
|
||||
function init(callback, onerror) {
|
||||
var blob = new Blob([ text ], {
|
||||
type : TEXT_PLAIN
|
||||
});
|
||||
blobReader = new BlobReader(blob);
|
||||
blobReader.init(function() {
|
||||
that.size = blobReader.size;
|
||||
callback();
|
||||
}, onerror);
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
blobReader.readUint8Array(index, length, callback, onerror);
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
TextReader.prototype = new Reader();
|
||||
TextReader.prototype.constructor = TextReader;
|
||||
|
||||
function Data64URIReader(dataURI) {
|
||||
var that = this, dataStart;
|
||||
|
||||
function init(callback) {
|
||||
var dataEnd = dataURI.length;
|
||||
while (dataURI.charAt(dataEnd - 1) == "=")
|
||||
dataEnd--;
|
||||
dataStart = dataURI.indexOf(",") + 1;
|
||||
that.size = Math.floor((dataEnd - dataStart) * 0.75);
|
||||
callback();
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback) {
|
||||
var i, data = getDataHelper(length);
|
||||
var start = Math.floor(index / 3) * 4;
|
||||
var end = Math.ceil((index + length) / 3) * 4;
|
||||
var bytes = obj.atob(dataURI.substring(start + dataStart, end + dataStart));
|
||||
var delta = index - Math.floor(start / 4) * 3;
|
||||
for (i = delta; i < delta + length; i++)
|
||||
data.array[i - delta] = bytes.charCodeAt(i);
|
||||
callback(data.array);
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
Data64URIReader.prototype = new Reader();
|
||||
Data64URIReader.prototype.constructor = Data64URIReader;
|
||||
|
||||
function BlobReader(blob) {
|
||||
var that = this;
|
||||
|
||||
function init(callback) {
|
||||
this.size = blob.size;
|
||||
callback();
|
||||
}
|
||||
|
||||
function readUint8Array(index, length, callback, onerror) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
callback(new Uint8Array(e.target.result));
|
||||
};
|
||||
reader.onerror = onerror;
|
||||
reader.readAsArrayBuffer(blobSlice(blob, index, length));
|
||||
}
|
||||
|
||||
that.size = 0;
|
||||
that.init = init;
|
||||
that.readUint8Array = readUint8Array;
|
||||
}
|
||||
BlobReader.prototype = new Reader();
|
||||
BlobReader.prototype.constructor = BlobReader;
|
||||
|
||||
// Writers
|
||||
|
||||
function Writer() {
|
||||
}
|
||||
Writer.prototype.getData = function(callback) {
|
||||
callback(this.data);
|
||||
};
|
||||
|
||||
function TextWriter(encoding) {
|
||||
var that = this, blob;
|
||||
|
||||
function init(callback) {
|
||||
blob = new Blob([], {
|
||||
type : TEXT_PLAIN
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
function writeUint8Array(array, callback) {
|
||||
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
|
||||
type : TEXT_PLAIN
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
function getData(callback, onerror) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
callback(e.target.result);
|
||||
};
|
||||
reader.onerror = onerror;
|
||||
reader.readAsText(blob, encoding);
|
||||
}
|
||||
|
||||
that.init = init;
|
||||
that.writeUint8Array = writeUint8Array;
|
||||
that.getData = getData;
|
||||
}
|
||||
TextWriter.prototype = new Writer();
|
||||
TextWriter.prototype.constructor = TextWriter;
|
||||
|
||||
function Data64URIWriter(contentType) {
|
||||
var that = this, data = "", pending = "";
|
||||
|
||||
function init(callback) {
|
||||
data += "data:" + (contentType || "") + ";base64,";
|
||||
callback();
|
||||
}
|
||||
|
||||
function writeUint8Array(array, callback) {
|
||||
var i, delta = pending.length, dataString = pending;
|
||||
pending = "";
|
||||
for (i = 0; i < (Math.floor((delta + array.length) / 3) * 3) - delta; i++)
|
||||
dataString += String.fromCharCode(array[i]);
|
||||
for (; i < array.length; i++)
|
||||
pending += String.fromCharCode(array[i]);
|
||||
if (dataString.length > 2)
|
||||
data += obj.btoa(dataString);
|
||||
else
|
||||
pending = dataString;
|
||||
callback();
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
callback(data + obj.btoa(pending));
|
||||
}
|
||||
|
||||
that.init = init;
|
||||
that.writeUint8Array = writeUint8Array;
|
||||
that.getData = getData;
|
||||
}
|
||||
Data64URIWriter.prototype = new Writer();
|
||||
Data64URIWriter.prototype.constructor = Data64URIWriter;
|
||||
|
||||
function BlobWriter(contentType) {
|
||||
var blob, that = this;
|
||||
|
||||
function init(callback) {
|
||||
blob = new Blob([], {
|
||||
type : contentType
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
function writeUint8Array(array, callback) {
|
||||
blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
|
||||
type : contentType
|
||||
});
|
||||
callback();
|
||||
}
|
||||
|
||||
function getData(callback) {
|
||||
callback(blob);
|
||||
}
|
||||
|
||||
that.init = init;
|
||||
that.writeUint8Array = writeUint8Array;
|
||||
that.getData = getData;
|
||||
}
|
||||
BlobWriter.prototype = new Writer();
|
||||
BlobWriter.prototype.constructor = BlobWriter;
|
||||
|
||||
// inflate/deflate core functions
|
||||
|
||||
function launchWorkerProcess(worker, reader, writer, offset, size, onappend, onprogress, onend, onreaderror, onwriteerror) {
|
||||
var chunkIndex = 0, index, outputSize;
|
||||
|
||||
function onflush() {
|
||||
worker.removeEventListener(MESSAGE_EVENT, onmessage, false);
|
||||
onend(outputSize);
|
||||
}
|
||||
|
||||
function onmessage(event) {
|
||||
var message = event.data, data = message.data;
|
||||
|
||||
if (message.onappend) {
|
||||
outputSize += data.length;
|
||||
writer.writeUint8Array(data, function() {
|
||||
onappend(false, data);
|
||||
step();
|
||||
}, onwriteerror);
|
||||
}
|
||||
if (message.onflush)
|
||||
if (data) {
|
||||
outputSize += data.length;
|
||||
writer.writeUint8Array(data, function() {
|
||||
onappend(false, data);
|
||||
onflush();
|
||||
}, onwriteerror);
|
||||
} else
|
||||
onflush();
|
||||
if (message.progress && onprogress)
|
||||
onprogress(index + message.current, size);
|
||||
}
|
||||
|
||||
function step() {
|
||||
index = chunkIndex * CHUNK_SIZE;
|
||||
if (index < size)
|
||||
reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
|
||||
worker.postMessage({
|
||||
append : true,
|
||||
data : array
|
||||
});
|
||||
chunkIndex++;
|
||||
if (onprogress)
|
||||
onprogress(index, size);
|
||||
onappend(true, array);
|
||||
}, onreaderror);
|
||||
else
|
||||
worker.postMessage({
|
||||
flush : true
|
||||
});
|
||||
}
|
||||
|
||||
outputSize = 0;
|
||||
worker.addEventListener(MESSAGE_EVENT, onmessage, false);
|
||||
step();
|
||||
}
|
||||
|
||||
function launchProcess(process, reader, writer, offset, size, onappend, onprogress, onend, onreaderror, onwriteerror) {
|
||||
var chunkIndex = 0, index, outputSize = 0;
|
||||
|
||||
function step() {
|
||||
var outputData;
|
||||
index = chunkIndex * CHUNK_SIZE;
|
||||
if (index < size)
|
||||
reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(inputData) {
|
||||
var outputData = process.append(inputData, function() {
|
||||
if (onprogress)
|
||||
onprogress(offset + index, size);
|
||||
});
|
||||
outputSize += outputData.length;
|
||||
onappend(true, inputData);
|
||||
writer.writeUint8Array(outputData, function() {
|
||||
onappend(false, outputData);
|
||||
chunkIndex++;
|
||||
setTimeout(step, 1);
|
||||
}, onwriteerror);
|
||||
if (onprogress)
|
||||
onprogress(index, size);
|
||||
}, onreaderror);
|
||||
else {
|
||||
outputData = process.flush();
|
||||
if (outputData) {
|
||||
outputSize += outputData.length;
|
||||
writer.writeUint8Array(outputData, function() {
|
||||
onappend(false, outputData);
|
||||
onend(outputSize);
|
||||
}, onwriteerror);
|
||||
} else
|
||||
onend(outputSize);
|
||||
}
|
||||
}
|
||||
|
||||
step();
|
||||
}
|
||||
|
||||
function inflate(reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
|
||||
var worker, crc32 = new Crc32();
|
||||
|
||||
function oninflateappend(sending, array) {
|
||||
if (computeCrc32 && !sending)
|
||||
crc32.append(array);
|
||||
}
|
||||
|
||||
function oninflateend(outputSize) {
|
||||
onend(outputSize, crc32.get());
|
||||
}
|
||||
|
||||
if (obj.zip.useWebWorkers) {
|
||||
worker = new Worker(obj.zip.workerScriptsPath + INFLATE_JS);
|
||||
launchWorkerProcess(worker, reader, writer, offset, size, oninflateappend, onprogress, oninflateend, onreaderror, onwriteerror);
|
||||
} else
|
||||
launchProcess(new obj.zip.Inflater(), reader, writer, offset, size, oninflateappend, onprogress, oninflateend, onreaderror, onwriteerror);
|
||||
return worker;
|
||||
}
|
||||
|
||||
function deflate(reader, writer, level, onend, onprogress, onreaderror, onwriteerror) {
|
||||
var worker, crc32 = new Crc32();
|
||||
|
||||
function ondeflateappend(sending, array) {
|
||||
if (sending)
|
||||
crc32.append(array);
|
||||
}
|
||||
|
||||
function ondeflateend(outputSize) {
|
||||
onend(outputSize, crc32.get());
|
||||
}
|
||||
|
||||
function onmessage() {
|
||||
worker.removeEventListener(MESSAGE_EVENT, onmessage, false);
|
||||
launchWorkerProcess(worker, reader, writer, 0, reader.size, ondeflateappend, onprogress, ondeflateend, onreaderror, onwriteerror);
|
||||
}
|
||||
|
||||
if (obj.zip.useWebWorkers) {
|
||||
worker = new Worker(obj.zip.workerScriptsPath + DEFLATE_JS);
|
||||
worker.addEventListener(MESSAGE_EVENT, onmessage, false);
|
||||
worker.postMessage({
|
||||
init : true,
|
||||
level : level
|
||||
});
|
||||
} else
|
||||
launchProcess(new obj.zip.Deflater(), reader, writer, 0, reader.size, ondeflateappend, onprogress, ondeflateend, onreaderror, onwriteerror);
|
||||
return worker;
|
||||
}
|
||||
|
||||
function copy(reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
|
||||
var chunkIndex = 0, crc32 = new Crc32();
|
||||
|
||||
function step() {
|
||||
var index = chunkIndex * CHUNK_SIZE;
|
||||
if (index < size)
|
||||
reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
|
||||
if (computeCrc32)
|
||||
crc32.append(array);
|
||||
if (onprogress)
|
||||
onprogress(index, size, array);
|
||||
writer.writeUint8Array(array, function() {
|
||||
chunkIndex++;
|
||||
step();
|
||||
}, onwriteerror);
|
||||
}, onreaderror);
|
||||
else
|
||||
onend(size, crc32.get());
|
||||
}
|
||||
|
||||
step();
|
||||
}
|
||||
|
||||
// ZipReader
|
||||
|
||||
function decodeASCII(str) {
|
||||
var i, out = "", charCode, extendedASCII = [ '\u00C7', '\u00FC', '\u00E9', '\u00E2', '\u00E4', '\u00E0', '\u00E5', '\u00E7', '\u00EA', '\u00EB',
|
||||
'\u00E8', '\u00EF', '\u00EE', '\u00EC', '\u00C4', '\u00C5', '\u00C9', '\u00E6', '\u00C6', '\u00F4', '\u00F6', '\u00F2', '\u00FB', '\u00F9',
|
||||
'\u00FF', '\u00D6', '\u00DC', '\u00F8', '\u00A3', '\u00D8', '\u00D7', '\u0192', '\u00E1', '\u00ED', '\u00F3', '\u00FA', '\u00F1', '\u00D1',
|
||||
'\u00AA', '\u00BA', '\u00BF', '\u00AE', '\u00AC', '\u00BD', '\u00BC', '\u00A1', '\u00AB', '\u00BB', '_', '_', '_', '\u00A6', '\u00A6',
|
||||
'\u00C1', '\u00C2', '\u00C0', '\u00A9', '\u00A6', '\u00A6', '+', '+', '\u00A2', '\u00A5', '+', '+', '-', '-', '+', '-', '+', '\u00E3',
|
||||
'\u00C3', '+', '+', '-', '-', '\u00A6', '-', '+', '\u00A4', '\u00F0', '\u00D0', '\u00CA', '\u00CB', '\u00C8', 'i', '\u00CD', '\u00CE',
|
||||
'\u00CF', '+', '+', '_', '_', '\u00A6', '\u00CC', '_', '\u00D3', '\u00DF', '\u00D4', '\u00D2', '\u00F5', '\u00D5', '\u00B5', '\u00FE',
|
||||
'\u00DE', '\u00DA', '\u00DB', '\u00D9', '\u00FD', '\u00DD', '\u00AF', '\u00B4', '\u00AD', '\u00B1', '_', '\u00BE', '\u00B6', '\u00A7',
|
||||
'\u00F7', '\u00B8', '\u00B0', '\u00A8', '\u00B7', '\u00B9', '\u00B3', '\u00B2', '_', ' ' ];
|
||||
for (i = 0; i < str.length; i++) {
|
||||
charCode = str.charCodeAt(i) & 0xFF;
|
||||
if (charCode > 127)
|
||||
out += extendedASCII[charCode - 128];
|
||||
else
|
||||
out += String.fromCharCode(charCode);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function decodeUTF8(string) {
|
||||
return decodeURIComponent(escape(string));
|
||||
}
|
||||
|
||||
function getString(bytes) {
|
||||
var i, str = "";
|
||||
for (i = 0; i < bytes.length; i++)
|
||||
str += String.fromCharCode(bytes[i]);
|
||||
return str;
|
||||
}
|
||||
|
||||
function getDate(timeRaw) {
|
||||
var date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
|
||||
try {
|
||||
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5,
|
||||
(time & 0x001F) * 2, 0);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
function readCommonHeader(entry, data, index, centralDirectory, onerror) {
|
||||
entry.version = data.view.getUint16(index, true);
|
||||
entry.bitFlag = data.view.getUint16(index + 2, true);
|
||||
entry.compressionMethod = data.view.getUint16(index + 4, true);
|
||||
entry.lastModDateRaw = data.view.getUint32(index + 6, true);
|
||||
entry.lastModDate = getDate(entry.lastModDateRaw);
|
||||
if ((entry.bitFlag & 0x01) === 0x01) {
|
||||
onerror(ERR_ENCRYPTED);
|
||||
return;
|
||||
}
|
||||
if (centralDirectory || (entry.bitFlag & 0x0008) != 0x0008) {
|
||||
entry.crc32 = data.view.getUint32(index + 10, true);
|
||||
entry.compressedSize = data.view.getUint32(index + 14, true);
|
||||
entry.uncompressedSize = data.view.getUint32(index + 18, true);
|
||||
}
|
||||
if (entry.compressedSize === 0xFFFFFFFF || entry.uncompressedSize === 0xFFFFFFFF) {
|
||||
onerror(ERR_ZIP64);
|
||||
return;
|
||||
}
|
||||
entry.filenameLength = data.view.getUint16(index + 22, true);
|
||||
entry.extraFieldLength = data.view.getUint16(index + 24, true);
|
||||
}
|
||||
|
||||
function createZipReader(reader, onerror) {
|
||||
function Entry() {
|
||||
}
|
||||
|
||||
Entry.prototype.getData = function(writer, onend, onprogress, checkCrc32) {
|
||||
var that = this, worker;
|
||||
|
||||
function terminate(callback, param) {
|
||||
if (worker)
|
||||
worker.terminate();
|
||||
worker = null;
|
||||
if (callback)
|
||||
callback(param);
|
||||
}
|
||||
|
||||
function testCrc32(crc32) {
|
||||
var dataCrc32 = getDataHelper(4);
|
||||
dataCrc32.view.setUint32(0, crc32);
|
||||
return that.crc32 == dataCrc32.view.getUint32(0);
|
||||
}
|
||||
|
||||
function getWriterData(uncompressedSize, crc32) {
|
||||
if (checkCrc32 && !testCrc32(crc32))
|
||||
onreaderror();
|
||||
else
|
||||
writer.getData(function(data) {
|
||||
terminate(onend, data);
|
||||
});
|
||||
}
|
||||
|
||||
function onreaderror() {
|
||||
terminate(onerror, ERR_READ_DATA);
|
||||
}
|
||||
|
||||
function onwriteerror() {
|
||||
terminate(onerror, ERR_WRITE_DATA);
|
||||
}
|
||||
|
||||
reader.readUint8Array(that.offset, 30, function(bytes) {
|
||||
var data = getDataHelper(bytes.length, bytes), dataOffset;
|
||||
if (data.view.getUint32(0) != 0x504b0304) {
|
||||
onerror(ERR_BAD_FORMAT);
|
||||
return;
|
||||
}
|
||||
readCommonHeader(that, data, 4, false, onerror);
|
||||
dataOffset = that.offset + 30 + that.filenameLength + that.extraFieldLength;
|
||||
writer.init(function() {
|
||||
if (that.compressionMethod === 0)
|
||||
copy(reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
|
||||
else
|
||||
worker = inflate(reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
|
||||
}, onwriteerror);
|
||||
}, onreaderror);
|
||||
};
|
||||
|
||||
function seekEOCDR(offset, entriesCallback) {
|
||||
reader.readUint8Array(reader.size - offset, offset, function(bytes) {
|
||||
var dataView = getDataHelper(bytes.length, bytes).view;
|
||||
if (dataView.getUint32(0) != 0x504b0506) {
|
||||
seekEOCDR(offset + 1, entriesCallback);
|
||||
} else {
|
||||
entriesCallback(dataView);
|
||||
}
|
||||
}, function() {
|
||||
onerror(ERR_READ);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getEntries : function(callback) {
|
||||
if (reader.size < 22) {
|
||||
onerror(ERR_BAD_FORMAT);
|
||||
return;
|
||||
}
|
||||
// look for End of central directory record
|
||||
seekEOCDR(22, function(dataView) {
|
||||
var datalength, fileslength;
|
||||
datalength = dataView.getUint32(16, true);
|
||||
fileslength = dataView.getUint16(8, true);
|
||||
reader.readUint8Array(datalength, reader.size - datalength, function(bytes) {
|
||||
var i, index = 0, entries = [], entry, filename, comment, data = getDataHelper(bytes.length, bytes);
|
||||
for (i = 0; i < fileslength; i++) {
|
||||
entry = new Entry();
|
||||
if (data.view.getUint32(index) != 0x504b0102) {
|
||||
onerror(ERR_BAD_FORMAT);
|
||||
return;
|
||||
}
|
||||
readCommonHeader(entry, data, index + 6, true, onerror);
|
||||
entry.commentLength = data.view.getUint16(index + 32, true);
|
||||
entry.directory = ((data.view.getUint8(index + 38) & 0x10) == 0x10);
|
||||
entry.offset = data.view.getUint32(index + 42, true);
|
||||
filename = getString(data.array.subarray(index + 46, index + 46 + entry.filenameLength));
|
||||
entry.filename = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(filename) : decodeASCII(filename);
|
||||
if (!entry.directory && entry.filename.charAt(entry.filename.length - 1) == "/")
|
||||
entry.directory = true;
|
||||
comment = getString(data.array.subarray(index + 46 + entry.filenameLength + entry.extraFieldLength, index + 46
|
||||
+ entry.filenameLength + entry.extraFieldLength + entry.commentLength));
|
||||
entry.comment = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(comment) : decodeASCII(comment);
|
||||
entries.push(entry);
|
||||
index += 46 + entry.filenameLength + entry.extraFieldLength + entry.commentLength;
|
||||
}
|
||||
callback(entries);
|
||||
}, function() {
|
||||
onerror(ERR_READ);
|
||||
});
|
||||
});
|
||||
},
|
||||
close : function(callback) {
|
||||
if (callback)
|
||||
callback();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ZipWriter
|
||||
|
||||
function encodeUTF8(string) {
|
||||
return unescape(encodeURIComponent(string));
|
||||
}
|
||||
|
||||
function getBytes(str) {
|
||||
var i, array = [];
|
||||
for (i = 0; i < str.length; i++)
|
||||
array.push(str.charCodeAt(i));
|
||||
return array;
|
||||
}
|
||||
|
||||
function createZipWriter(writer, onerror, dontDeflate) {
|
||||
var worker, files = {}, filenames = [], datalength = 0;
|
||||
|
||||
function terminate(callback, message) {
|
||||
if (worker)
|
||||
worker.terminate();
|
||||
worker = null;
|
||||
if (callback)
|
||||
callback(message);
|
||||
}
|
||||
|
||||
function onwriteerror() {
|
||||
terminate(onerror, ERR_WRITE);
|
||||
}
|
||||
|
||||
function onreaderror() {
|
||||
terminate(onerror, ERR_READ_DATA);
|
||||
}
|
||||
|
||||
return {
|
||||
add : function(name, reader, onend, onprogress, options) {
|
||||
var header, filename, date;
|
||||
|
||||
function writeHeader(callback) {
|
||||
var data;
|
||||
date = options.lastModDate || new Date();
|
||||
header = getDataHelper(26);
|
||||
files[name] = {
|
||||
headerArray : header.array,
|
||||
directory : options.directory,
|
||||
filename : filename,
|
||||
offset : datalength,
|
||||
comment : getBytes(encodeUTF8(options.comment || ""))
|
||||
};
|
||||
header.view.setUint32(0, 0x14000808);
|
||||
if (options.version)
|
||||
header.view.setUint8(0, options.version);
|
||||
if (!dontDeflate && options.level !== 0 && !options.directory)
|
||||
header.view.setUint16(4, 0x0800);
|
||||
header.view.setUint16(6, (((date.getHours() << 6) | date.getMinutes()) << 5) | date.getSeconds() / 2, true);
|
||||
header.view.setUint16(8, ((((date.getFullYear() - 1980) << 4) | (date.getMonth() + 1)) << 5) | date.getDate(), true);
|
||||
header.view.setUint16(22, filename.length, true);
|
||||
data = getDataHelper(30 + filename.length);
|
||||
data.view.setUint32(0, 0x504b0304);
|
||||
data.array.set(header.array, 4);
|
||||
data.array.set(filename, 30);
|
||||
datalength += data.array.length;
|
||||
writer.writeUint8Array(data.array, callback, onwriteerror);
|
||||
}
|
||||
|
||||
function writeFooter(compressedLength, crc32) {
|
||||
var footer = getDataHelper(16);
|
||||
datalength += compressedLength || 0;
|
||||
footer.view.setUint32(0, 0x504b0708);
|
||||
if (typeof crc32 != "undefined") {
|
||||
header.view.setUint32(10, crc32, true);
|
||||
footer.view.setUint32(4, crc32, true);
|
||||
}
|
||||
if (reader) {
|
||||
footer.view.setUint32(8, compressedLength, true);
|
||||
header.view.setUint32(14, compressedLength, true);
|
||||
footer.view.setUint32(12, reader.size, true);
|
||||
header.view.setUint32(18, reader.size, true);
|
||||
}
|
||||
writer.writeUint8Array(footer.array, function() {
|
||||
datalength += 16;
|
||||
terminate(onend);
|
||||
}, onwriteerror);
|
||||
}
|
||||
|
||||
function writeFile() {
|
||||
options = options || {};
|
||||
name = name.trim();
|
||||
if (options.directory && name.charAt(name.length - 1) != "/")
|
||||
name += "/";
|
||||
if (files.hasOwnProperty(name)) {
|
||||
onerror(ERR_DUPLICATED_NAME);
|
||||
return;
|
||||
}
|
||||
filename = getBytes(encodeUTF8(name));
|
||||
filenames.push(name);
|
||||
writeHeader(function() {
|
||||
if (reader)
|
||||
if (dontDeflate || options.level === 0)
|
||||
copy(reader, writer, 0, reader.size, true, writeFooter, onprogress, onreaderror, onwriteerror);
|
||||
else
|
||||
worker = deflate(reader, writer, options.level, writeFooter, onprogress, onreaderror, onwriteerror);
|
||||
else
|
||||
writeFooter();
|
||||
}, onwriteerror);
|
||||
}
|
||||
|
||||
if (reader)
|
||||
reader.init(writeFile, onreaderror);
|
||||
else
|
||||
writeFile();
|
||||
},
|
||||
close : function(callback) {
|
||||
var data, length = 0, index = 0, indexFilename, file;
|
||||
for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
|
||||
file = files[filenames[indexFilename]];
|
||||
length += 46 + file.filename.length + file.comment.length;
|
||||
}
|
||||
data = getDataHelper(length + 22);
|
||||
for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
|
||||
file = files[filenames[indexFilename]];
|
||||
data.view.setUint32(index, 0x504b0102);
|
||||
data.view.setUint16(index + 4, 0x1400);
|
||||
data.array.set(file.headerArray, index + 6);
|
||||
data.view.setUint16(index + 32, file.comment.length, true);
|
||||
if (file.directory)
|
||||
data.view.setUint8(index + 38, 0x10);
|
||||
data.view.setUint32(index + 42, file.offset, true);
|
||||
data.array.set(file.filename, index + 46);
|
||||
data.array.set(file.comment, index + 46 + file.filename.length);
|
||||
index += 46 + file.filename.length + file.comment.length;
|
||||
}
|
||||
data.view.setUint32(index, 0x504b0506);
|
||||
data.view.setUint16(index + 8, filenames.length, true);
|
||||
data.view.setUint16(index + 10, filenames.length, true);
|
||||
data.view.setUint32(index + 12, length, true);
|
||||
data.view.setUint32(index + 16, datalength, true);
|
||||
writer.writeUint8Array(data.array, function() {
|
||||
terminate(function() {
|
||||
writer.getData(callback);
|
||||
});
|
||||
}, onwriteerror);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
obj.zip = {
|
||||
Reader : Reader,
|
||||
Writer : Writer,
|
||||
BlobReader : BlobReader,
|
||||
Data64URIReader : Data64URIReader,
|
||||
TextReader : TextReader,
|
||||
BlobWriter : BlobWriter,
|
||||
Data64URIWriter : Data64URIWriter,
|
||||
TextWriter : TextWriter,
|
||||
createReader : function(reader, callback, onerror) {
|
||||
reader.init(function() {
|
||||
callback(createZipReader(reader, onerror));
|
||||
}, onerror);
|
||||
},
|
||||
createWriter : function(writer, callback, onerror, dontDeflate) {
|
||||
writer.init(function() {
|
||||
callback(createZipWriter(writer, onerror, dontDeflate));
|
||||
}, onerror);
|
||||
},
|
||||
workerScriptsPath : "",
|
||||
useWebWorkers : true
|
||||
};
|
||||
|
||||
})(this);
|
30
files_reader/js/libs/zip.min.js
vendored
Normal file
30
files_reader/js/libs/zip.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue