testing out reading pages straight from a cbz file

This commit is contained in:
Bala Clark 2013-03-25 07:32:37 +01:00
parent 5d20759dcc
commit 291b1e411f
53 changed files with 10269 additions and 0 deletions

760
lib/zip.js/tests/arraybuffer.js Executable file
View file

@ -0,0 +1,760 @@
// Code can be found at: http://www.calormen.com/polyfill/typedarray.js
/*
$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$
*/
// Original can be found at: https://bitbucket.org/lindenlab/llsd
// Modifications by Joshua Bell inexorabletash@hotmail.com
// * Restructure the creation of types and exporting to global namespace
// * Allow no arguments to DataView constructor
// * Work cross-frame with native arrays/shimmed DataView
// * Corrected Object.defineProperty shim for IE8
// 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[])
(function(global) {
"use strict";
var USE_NATIVE_IF_AVAILABLE = true;
// Approximations of internal ECMAScript conversion functions
var ECMAScript = (function() {
// Stash a copy in case other scripts modify these
var opts = Object.prototype.toString, ophop = Object.prototype.hasOwnProperty;
return {
// Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues:
Class : function(v) {
return opts.call(v).replace(/^\[object *|\]$/g, '');
},
HasProperty : function(o, p) {
return p in o;
},
HasOwnProperty : function(o, p) {
return ophop.call(o, p);
},
IsCallable : function(o) {
return typeof o === 'function';
},
ToInt32 : function(v) {
return v >> 0;
},
ToUint32 : function(v) {
return v >>> 0;
}
};
}());
// Create an INDEX_SIZE_ERR event - intentionally induces a DOM error if possible
function new_INDEX_SIZE_ERR() {
try {
if (document) {
// raises DOMException(INDEX_SIZE_ERR)
document.createTextNode("").splitText(1);
}
return new RangeError("INDEX_SIZE_ERR");
} catch (e) {
return e;
}
}
// 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
// (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but
// note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless)
if (!Object.defineProperty || !(function() {
try {
Object.defineProperty({}, 'x', {});
return true;
} catch (e) {
return false;
}
}())) {
Object.defineProperty = function(o, p, desc) {
if (!o === Object(o)) {
throw new TypeError("Object.defineProperty called on non-object");
}
if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) {
Object.prototype.__defineGetter__.call(o, p, desc.get);
}
if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) {
Object.prototype.__defineSetter__.call(o, p, desc.set);
}
if (ECMAScript.HasProperty(desc, 'value')) {
o[p] = desc.value;
}
return o;
};
}
if (!Object.getOwnPropertyNames) {
Object.getOwnPropertyNames = function getOwnPropertyNames(o) {
if (o !== Object(o)) {
throw new TypeError("Object.getOwnPropertyNames called on non-object");
}
var props = [], p;
for (p in o) {
if (ECMAScript.HasOwnProperty(o, p)) {
props.push(p);
}
}
return props;
};
}
// 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 (v !== v) {
// NaN
// 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);
}
//
// 3 The ArrayBuffer Type
//
(function() {
/** @constructor */
var ArrayBuffer = function ArrayBuffer(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
/** @constructor */
var ArrayBufferView = function ArrayBufferView() {
// 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;
if (!arguments.length || typeof arguments[0] === 'number') {
// Constructor(unsigned long length)
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;
} else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
// Constructor(TypedArray array)
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));
}
} else if (typeof arguments[0] === 'object' && !(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
// Constructor(sequence<type> array)
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));
}
} else if (typeof arguments[0] === 'object' && (arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
// Constructor(ArrayBuffer buffer,
// optional unsigned long byteOffset, optional unsigned long length)
this.buffer = buffer;
this.byteOffset = ECMAScript.ToUint32(byteOffset);
if (this.byteOffset > this.buffer.byteLength) {
throw new_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.
// throw new_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) {
throw new_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) {
throw new_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;
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) {
// throw new_INDEX_SIZE_ERR(); // Array index out of range
return (void 0); // 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) {
// throw new_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;
if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
// void set(TypedArray array, optional unsigned long offset);
array = arguments[0];
offset = ECMAScript.ToUint32(arguments[1]);
if (offset + array.length > this.length) {
throw new_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];
}
}
} else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
// void set(sequence<type> array, optional unsigned long offset);
sequence = arguments[0];
len = ECMAScript.ToUint32(sequence.length);
offset = ECMAScript.ToUint32(arguments[1]);
if (offset + len > this.length) {
throw new_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;
}
var Int8Array = makeTypedArrayConstructor(1, packInt8, unpackInt8);
var Uint8Array = makeTypedArrayConstructor(1, packUint8, unpackUint8);
var Int16Array = makeTypedArrayConstructor(2, packInt16, unpackInt16);
var Uint16Array = makeTypedArrayConstructor(2, packUint16, unpackUint16);
var Int32Array = makeTypedArrayConstructor(4, packInt32, unpackInt32);
var Uint32Array = makeTypedArrayConstructor(4, packUint32, unpackUint32);
var Float32Array = makeTypedArrayConstructor(4, packFloat32, unpackFloat32);
var Float64Array = makeTypedArrayConstructor(8, packFloat64, unpackFloat64);
if (USE_NATIVE_IF_AVAILABLE) {
global.ArrayBuffer = global.ArrayBuffer || ArrayBuffer;
global.Int8Array = global.Int8Array || Int8Array;
global.Uint8Array = global.Uint8Array || Uint8Array;
global.Int16Array = global.Int16Array || Int16Array;
global.Uint16Array = global.Uint16Array || Uint16Array;
global.Int32Array = global.Int32Array || Int32Array;
global.Uint32Array = global.Uint32Array || Uint32Array;
global.Float32Array = global.Float32Array || Float32Array;
global.Float64Array = global.Float64Array || Float64Array;
} else {
global.ArrayBuffer = ArrayBuffer;
global.Int8Array = Int8Array;
global.Uint8Array = Uint8Array;
global.Int16Array = Int16Array;
global.Uint16Array = Uint16Array;
global.Int32Array = Int32Array;
global.Uint32Array = Uint32Array;
global.Float32Array = Float32Array;
global.Float64Array = Float64Array;
}
}());
//
// 6 The DataView View Type
//
(function() {
function r(array, index) {
return ECMAScript.IsCallable(array.get) ? array.get(index) : 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)
/** @constructor */
var DataView = function DataView(buffer, byteOffset, byteLength) {
if (arguments.length === 0) {
buffer = new ArrayBuffer(0);
} else if (!(buffer instanceof ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) {
throw new TypeError("TypeError");
}
this.buffer = buffer || new ArrayBuffer(0);
this.byteOffset = ECMAScript.ToUint32(byteOffset);
if (this.byteOffset > this.buffer.byteLength) {
throw new_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) {
throw new_INDEX_SIZE_ERR(); // byteOffset and length reference an area beyond the end of the buffer
}
configureProperties(this);
};
// TODO: Reintroduce this to get correct hierarchy
// if (typeof ArrayBufferView === 'function') {
// DataView.prototype = new ArrayBufferView();
// }
function makeDataView_getter(arrayType) {
return function(byteOffset, littleEndian) {
byteOffset = ECMAScript.ToUint32(byteOffset);
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
throw new_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) {
byteOffset = ECMAScript.ToUint32(byteOffset);
if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
throw new_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);
if (USE_NATIVE_IF_AVAILABLE) {
global.DataView = global.DataView || DataView;
} else {
global.DataView = DataView;
}
}());
}(this));

58
lib/zip.js/tests/base64.js Executable file
View file

@ -0,0 +1,58 @@
/// Code can be found at: https://gist.github.com/1284012
(function() {
var a64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', a256 = {
indexOf : function(c) {
return c.charCodeAt(0);
},
charAt : String.fromCharCode
};
function code(s, discard, alpha, beta, w1, w2) {
s = String(s);
var b = 0, x = '', i, c, bs = 1, sb = 1, length = s.length, tmp;
for (i = 0; i < length || (!discard && sb > 1); i += 1) {
b *= w1;
bs *= w1;
if (i < length) {
c = alpha.indexOf(s.charAt(i));
if (c <= -1 || c >= w1) {
throw new RangeError();
}
sb *= w1;
b += c;
}
while (bs >= w2) {
bs /= w2;
if (sb > 1) {
tmp = b;
b %= bs;
x += beta.charAt((tmp - b) / bs);
sb /= w2;
}
}
}
return x;
}
if (!("btoa" in window))
window.btoa = function(s) {
s = code(s, false, a256, a64, 256, 64);
return s + '===='.slice((s.length % 4) || 4);
};
if (!("atob" in window))
window.atob = function(s) {
var i;
s = String(s).split('=');
for (i = s.length - 1; i >= 0; i -= 1) {
if (s[i].length % 4 === 1) {
throw new RangeError();
}
s[i] = code(s[i], true, a64, a256, 64, 256);
}
return s.join('');
};
})();

212
lib/zip.js/tests/dataview.js Executable file
View file

@ -0,0 +1,212 @@
/*
* DataView.js:
* An implementation of the DataView class on top of typed arrays.
* Useful for Firefox 4 which implements TypedArrays but not DataView.
*
* Copyright 2011, David Flanagan
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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.
*/
"use strict";
(function(global) {
// If DataView already exists, do nothing
if (global.DataView) return;
// If ArrayBuffer is not supported, fail with an error
if (!global.ArrayBuffer) fail("ArrayBuffer not supported");
// If ES5 is not supported, fail
if (!Object.defineProperties) fail("This module requires ECMAScript 5");
// Figure if the platform is natively little-endian.
// If the integer 0x00000001 is arranged in memory as 01 00 00 00 then
// we're on a little endian platform. On a big-endian platform we'd get
// get bytes 00 00 00 01 instead.
var nativele = new Int8Array(new Int32Array([1]).buffer)[0] === 1;
// A temporary array for copying or reversing bytes into.
// Since js is single-threaded, we only need this one static copy
var temp = new Uint8Array(8);
// The DataView() constructor
global.DataView = function DataView(buffer, offset, length) {
if (!(buffer instanceof ArrayBuffer)) fail("Bad ArrayBuffer");
// Default values for omitted arguments
offset = offset || 0;
length = length || (buffer.byteLength - offset);
if (offset < 0 || length < 0 || offset + length > buffer.byteLength) fail("Illegal offset and/or length");
// Define the 3 read-only, non-enumerable ArrayBufferView properties
Object.defineProperties(this, {
buffer: {
value: buffer,
enumerable: false,
writable: false,
configurable: false
},
byteOffset: {
value: offset,
enumerable: false,
writable: false,
configurable: false
},
byteLength: {
value: length,
enumerable: false,
writable: false,
configurable: false
},
_bytes: {
value: new Uint8Array(buffer, offset, length),
enumerable: false,
writable: false,
configurable: false
}
});
}
// The DataView prototype object
global.DataView.prototype = {
constructor: DataView,
getInt8: function getInt8(offset) {
return get(this, Int8Array, 1, offset);
},
getUint8: function getUint8(offset) {
return get(this, Uint8Array, 1, offset);
},
getInt16: function getInt16(offset, le) {
return get(this, Int16Array, 2, offset, le);
},
getUint16: function getUint16(offset, le) {
return get(this, Uint16Array, 2, offset, le);
},
getInt32: function getInt32(offset, le) {
return get(this, Int32Array, 4, offset, le);
},
getUint32: function getUint32(offset, le) {
return get(this, Uint32Array, 4, offset, le);
},
getFloat32: function getFloat32(offset, le) {
return get(this, Float32Array, 4, offset, le);
},
getFloat64: function getFloat32(offset, le) {
return get(this, Float64Array, 8, offset, le);
},
setInt8: function setInt8(offset, value) {
set(this, Int8Array, 1, offset, value);
},
setUint8: function setUint8(offset, value) {
set(this, Uint8Array, 1, offset, value);
},
setInt16: function setInt16(offset, value, le) {
set(this, Int16Array, 2, offset, value, le);
},
setUint16: function setUint16(offset, value, le) {
set(this, Uint16Array, 2, offset, value, le);
},
setInt32: function setInt32(offset, value, le) {
set(this, Int32Array, 4, offset, value, le);
},
setUint32: function setUint32(offset, value, le) {
set(this, Uint32Array, 4, offset, value, le);
},
setFloat32: function setFloat32(offset, value, le) {
set(this, Float32Array, 4, offset, value, le);
},
setFloat64: function setFloat64(offset, value, le) {
set(this, Float64Array, 8, offset, value, le);
}
};
// The get() utility function used by the get methods
function get(view, type, size, offset, le) {
if (offset === undefined) fail("Missing required offset argument");
if (offset < 0 || offset + size > view.byteLength) fail("Invalid index: " + offset);
if (size === 1 || !! le === nativele) {
// This is the easy case: the desired endianness
// matches the native endianness.
// Typed arrays require proper alignment. DataView does not.
if ((view.byteOffset + offset) % size === 0) return (new type(view.buffer, view.byteOffset + offset, 1))[0];
else {
// Copy bytes into the temp array, to fix alignment
for (var i = 0; i < size; i++)
temp[i] = view._bytes[offset + i];
// Now wrap that buffer with an array of the desired type
return (new type(temp.buffer))[0];
}
} else {
// If the native endianness doesn't match the desired, then
// we have to reverse the bytes
for (var i = 0; i < size; i++)
temp[size - i - 1] = view._bytes[offset + i];
return (new type(temp.buffer))[0];
}
}
// The set() utility function used by the set methods
function set(view, type, size, offset, value, le) {
if (offset === undefined) fail("Missing required offset argument");
if (value === undefined) fail("Missing required value argument");
if (offset < 0 || offset + size > view.byteLength) fail("Invalid index: " + offset);
if (size === 1 || !! le === nativele) {
// This is the easy case: the desired endianness
// matches the native endianness.
if ((view.byteOffset + offset) % size === 0) {
(new type(view.buffer, view.byteOffset + offset, 1))[0] = value;
} else {
(new type(temp.buffer))[0] = value;
// Now copy the bytes into the view's buffer
for (var i = 0; i < size; i++)
view._bytes[i + offset] = temp[i];
}
} else {
// If the native endianness doesn't match the desired, then
// we have to reverse the bytes
// Store the value into our temporary buffer
(new type(temp.buffer))[0] = value;
// Now copy the bytes, in reverse order, into the view's buffer
for (var i = 0; i < size; i++)
view._bytes[offset + i] = temp[size - 1 - i];
}
}
function fail(msg) {
throw new Error(msg);
}
}(this));

1
lib/zip.js/tests/lorem.txt Executable file
View file

@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.

BIN
lib/zip.js/tests/lorem.zip Executable file

Binary file not shown.

BIN
lib/zip.js/tests/lorem2.zip Executable file

Binary file not shown.

BIN
lib/zip.js/tests/lorem_store.zip Executable file

Binary file not shown.

13
lib/zip.js/tests/test1.html Executable file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo Blob</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../mime-types.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test1.js"></script>
</body>
</html>

46
lib/zip.js/tests/test1.js Executable file
View file

@ -0,0 +1,46 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var blob;
function onerror(message) {
console.error(message);
}
function zipBlob(blob, callback) {
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
zipWriter.add(FILENAME, new zip.BlobReader(blob), function() {
zipWriter.close(callback);
});
}, onerror);
}
function unzipBlob(blob, callback) {
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logBlobText(blob) {
var reader = new FileReader();
reader.onload = function(e) {
console.log(e.target.result);
console.log("--------------");
};
reader.readAsText(blob);
}
zip.workerScriptsPath = "../";
blob = new Blob([ TEXT_CONTENT ], {
type : zip.getMimeType(FILENAME)
});
logBlobText(blob);
zipBlob(blob, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedBlob) {
logBlobText(unzippedBlob);
});
});

14
lib/zip.js/tests/test10.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo STORE unzip</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test10.js"></script>
</body>
</html>

34
lib/zip.js/tests/test10.js Executable file
View file

@ -0,0 +1,34 @@
var URL = "lorem_store.zip";
var zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipImportedZip(callback) {
var directory = zipFs.root.addDirectory("import");
directory.importHttpContent(URL, false, function() {
zipFs.exportBlob(callback);
}, onerror);
}
function unzipBlob(blob, callback) {
zipFs.importBlob(blob, function() {
var directory = zipFs.root.getChildByName("import");
var firstEntry = directory.children[0];
firstEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
zipImportedZip(function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedText) {
logText(unzippedText);
});
});

14
lib/zip.js/tests/test11.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo ZipEntry.prototype.getFileEntry (File)</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test11.js"></script>
</body>
</html>

67
lib/zip.js/tests/test11.js Executable file
View file

@ -0,0 +1,67 @@
var requestFileSystem = window.webkitRequestFileSystem || window.mozRequestFileSystem || window.msRequestFileSystem || window.requestFileSystem;
var URL = "lorem.zip", FILENAME = "lorem.txt";
var filesystem, zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
}
removeNextEntry();
}, onerror);
}
function importZipToFilesystem(callback) {
zipFs.importHttpContent(URL, false, function() {
filesystem.root.getFile(FILENAME, {
create : true
}, function(fileEntry) {
var zippedFile = zipFs.root.getChildByName(FILENAME);
zippedFile.getFileEntry(fileEntry, callback, null, onerror);
}, onerror);
}, onerror);
}
function logFile(file) {
var reader = new FileReader();
reader.onload = function(event) {
console.log(event.target.result);
console.log("--------------");
};
reader.onerror = onerror;
reader.readAsText(file);
}
function test() {
importZipToFilesystem(function() {
filesystem.root.getFile(FILENAME, null, function(fileEntry) {
fileEntry.file(logFile, onerror);
}, onerror);
}, onerror);
}
zip.workerScriptsPath = "../";
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, test, onerror);
}, onerror);

14
lib/zip.js/tests/test12.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo ZipEntry.prototype.getFileEntry (Directory)</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test12.js"></script>
</body>
</html>

66
lib/zip.js/tests/test12.js Executable file
View file

@ -0,0 +1,66 @@
var requestFileSystem = window.webkitRequestFileSystem || window.mozRequestFileSystem || window.msRequestFileSystem || window.requestFileSystem;
var URL = "lorem2.zip";
var filesystem, zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
}
removeNextEntry();
}, onerror);
}
function importZipToFilesystem(callback) {
zipFs.importHttpContent(URL, false, function() {
zipFs.root.getFileEntry(filesystem.root, callback, null, onerror);
}, onerror);
}
function logFile(file) {
var reader = new FileReader();
reader.onload = function(event) {
console.log(event.target.result);
console.log("--------------");
};
reader.onerror = onerror;
reader.readAsText(file);
}
function test() {
importZipToFilesystem(function() {
filesystem.root.getDirectory("aaa", null, function(directoryEntry) {
directoryEntry.getDirectory("ccc", null, function(directoryEntry) {
directoryEntry.getFile("lorem.txt", null, function(fileEntry) {
fileEntry.file(logFile, onerror);
}, onerror);
}, onerror);
}, onerror);
}, onerror);
}
zip.workerScriptsPath = "../";
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, test, test);
}, onerror);

13
lib/zip.js/tests/test13.html Executable file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo ZipEntry.prototype.addFileEntry (File)</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test13.js"></script>
</body>
</html>

74
lib/zip.js/tests/test13.js Executable file
View file

@ -0,0 +1,74 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var requestFileSystem = window.webkitRequestFileSystem || window.mozRequestFileSystem || window.msRequestFileSystem || window.requestFileSystem;
var filesystem, zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
}
removeNextEntry();
}, onerror);
}
function addFileEntryAndReadFile(fileEntry, callback) {
zipFs.root.addFileEntry(fileEntry, function() {
var zipEntry = zipFs.root.getChildByName("lorem.txt");
zipEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
function initFileSystem(callback) {
filesystem.root.getFile("lorem.txt", {
create : true
}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
writer.onwrite = function() {
callback(fileEntry);
};
writer.onerror = onerror;
writer.write(new Blob([ TEXT_CONTENT ], {
type : "text/plain"
}));
}, onerror);
}, onerror);
}
function test() {
initFileSystem(function(fileEntry) {
addFileEntryAndReadFile(fileEntry, function(text) {
logText(text);
}, onerror);
});
}
zip.workerScriptsPath = "../";
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, test, onerror);
}, onerror);

13
lib/zip.js/tests/test14.html Executable file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo ZipEntry.prototype.addFileEntry (Directory)</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test14.js"></script>
</body>
</html>

80
lib/zip.js/tests/test14.js Executable file
View file

@ -0,0 +1,80 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var requestFileSystem = window.webkitRequestFileSystem || window.mozRequestFileSystem || window.msRequestFileSystem || window.requestFileSystem;
var filesystem, zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
}
removeNextEntry();
}, onerror);
}
function addDirectoryAndReadFile(callback) {
zipFs.root.addFileEntry(filesystem.root, function() {
var zipEntry = zipFs.root.getChildByName("aaa").getChildByName("ccc").getChildByName("lorem.txt");
zipEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
function initFileSystem(callback) {
filesystem.root.getDirectory("aaa", {
create : true
}, function(directoryEntry) {
directoryEntry.getDirectory("ccc", {
create : true
}, function(directoryEntry) {
directoryEntry.getFile("lorem.txt", {
create : true
}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
writer.onwrite = callback;
writer.onerror = onerror;
writer.write(new Blob([ TEXT_CONTENT ], {
type : "text/plain"
}));
}, onerror);
}, onerror);
}, onerror);
}, onerror);
}
function test() {
initFileSystem(function() {
addDirectoryAndReadFile(function(text) {
logText(text);
}, onerror);
});
}
zip.workerScriptsPath = "../";
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, test, onerror);
}, onerror);

12
lib/zip.js/tests/test15.html Executable file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo parallel reads</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test15.js"></script>
</body>
</html>

60
lib/zip.js/tests/test15.js Executable file
View file

@ -0,0 +1,60 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
function onerror(message) {
console.error(message);
}
function zipBlobs(blobs, callback) {
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
var index = 0;
function next() {
if (index < blobs.length)
zipWriter.add(blobs[index].name, new zip.BlobReader(blobs[index].blob), function() {
index++;
next();
});
else
zipWriter.close(callback);
}
next();
}, onerror);
}
function unzipBlob(blob) {
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
zipReader.getEntries(function(entries) {
var i;
for (i = 0; i < entries.length; i++)
entries[i].getData(new zip.TextWriter(), function(text) {
logText(text);
});
});
}, onerror);
}
function getBlob() {
return new Blob([ TEXT_CONTENT ], {
type : "text/plain"
});
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
var blobs = [ {
name : "lorem1.txt",
blob : getBlob()
}, {
name : "lorem2.txt",
blob : getBlob()
} ];
zipBlobs(blobs, function(zippedBlob) {
unzipBlob(zippedBlob);
});

14
lib/zip.js/tests/test16.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo without web workers</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../deflate.js"></script>
<script type="text/javascript" src="../inflate.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test16.js"></script>
</body>
</html>

46
lib/zip.js/tests/test16.js Executable file
View file

@ -0,0 +1,46 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var blob;
function onerror(message) {
console.error(message);
}
function zipBlob(blob, callback) {
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
zipWriter.add(FILENAME, new zip.BlobReader(blob), function() {
zipWriter.close(callback);
});
}, onerror);
}
function unzipBlob(blob, callback) {
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.BlobWriter("text/plain"), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logBlobText(blob) {
var reader = new FileReader();
reader.onload = function(e) {
console.log(e.target.result);
console.log("--------------");
};
reader.readAsText(blob);
}
zip.useWebWorkers = false;
blob = new Blob([ TEXT_CONTENT ], {
type : "text/plain"
});
logBlobText(blob);
zipBlob(blob, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedBlob) {
logBlobText(unzippedBlob);
});
});

15
lib/zip.js/tests/test17.html Executable file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo base 64 (compatible with IE, Firefox, Chrome, Safari)</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../deflate.js"></script>
<script type="text/javascript" src="../inflate.js"></script>
<script type="text/javascript" src="arraybuffer.js"></script>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript" src="test17.js"></script>
</body>
</html>

41
lib/zip.js/tests/test17.js Executable file
View file

@ -0,0 +1,41 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var dataURI = "data:text/plain;base64," + btoa(TEXT_CONTENT);
function onerror(message) {
console.error(message);
}
function zipDataURI(dataURI, callback) {
zip.createWriter(new zip.Data64URIWriter("application/zip"), function(zipWriter) {
zipWriter.add(FILENAME, new zip.Data64URIReader(dataURI), function() {
zipWriter.close(callback);
});
}, onerror);
}
function unzipDataURI(dataURI, callback) {
zip.createReader(new zip.Data64URIReader(dataURI), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.Data64URIWriter("text/plain"), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logDataURI(dataURI) {
console.log(dataURI);
console.log("--------------");
}
zip.useWebWorkers = false;
logDataURI(dataURI);
zipDataURI(dataURI, function(zippedData64) {
logDataURI(zippedData64);
unzipDataURI(zippedData64, function(unzippedDataURI) {
logDataURI(unzippedDataURI);
});
});

16
lib/zip.js/tests/test18.html Executable file
View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo ArrayBuffer</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="../deflate.js"></script>
<script type="text/javascript" src="../inflate.js"></script>
<script type="text/javascript" src="arraybuffer.js"></script>
<script type="text/javascript" src="base64.js"></script>
<script type="text/javascript" src="test18.js"></script>
</body>
</html>

46
lib/zip.js/tests/test18.js Executable file
View file

@ -0,0 +1,46 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var arrayBuffer;
function onerror(message) {
console.error(message);
}
function zipArrayBuffer(arrayBuffer, callback) {
zip.createWriter(new zip.ArrayBufferWriter(), function(zipWriter) {
zipWriter.add(FILENAME, new zip.ArrayBufferReader(arrayBuffer), function() {
zipWriter.close(callback);
});
}, onerror);
}
function unzipArrayBuffer(arrayBuffer, callback) {
zip.createReader(new zip.ArrayBufferReader(arrayBuffer), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.ArrayBufferWriter(), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logArrayBufferText(arrayBuffer) {
var array = new Uint8Array(arrayBuffer);
var str = "";
Array.prototype.forEach.call(array, function(code) {
str += String.fromCharCode(code);
});
console.log(str);
}
zip.workerScriptsPath = "../";
arrayBuffer = new Uint8Array(Array.prototype.map.call(TEXT_CONTENT, function(c) {
return c.charCodeAt(0);
})).buffer;
logArrayBufferText(arrayBuffer);
zipArrayBuffer(arrayBuffer, function(zippedArrayBuffer) {
unzipArrayBuffer(zippedArrayBuffer, function(unzippedArrayBuffer) {
logArrayBufferText(unzippedArrayBuffer);
});
});

14
lib/zip.js/tests/test2.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo File</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" src="test2.js"></script>
</body>
</html>

49
lib/zip.js/tests/test2.js Executable file
View file

@ -0,0 +1,49 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var blob, requestFileSystem = this.webkitRequestFileSystem || this.mozRequestFileSystem || this.requestFileSystem;
function onerror(message) {
console.error(message);
}
function zipBlob(blob, callback) {
createTempFile(function(fileEntry) {
zip.createWriter(new zip.FileWriter(fileEntry, "application/zip"), function(zipWriter) {
zipWriter.add(FILENAME, new zip.BlobReader(blob), function() {
zipWriter.close(callback);
});
}, onerror);
});
}
function unzipBlob(blob, callback) {
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.BlobWriter("text/plain"), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logBlobText(blob) {
var reader = new FileReader();
reader.onload = function(e) {
console.log(e.target.result);
console.log("--------------");
};
reader.readAsText(blob);
}
zip.workerScriptsPath = "../";
blob = new Blob([TEXT_CONTENT], {
type: "text/plain"
});
logBlobText(blob);
zipBlob(blob, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedBlob) {
logBlobText(unzippedBlob);
});
});

14
lib/zip.js/tests/test3.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo filesystem API</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../mime-types.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test3.js"></script>
</body>
</html>

40
lib/zip.js/tests/test3.js Executable file
View file

@ -0,0 +1,40 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var blob, zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipBlob(blob, callback) {
zipFs.root.addBlob(FILENAME, blob);
zipFs.exportBlob(callback);
}
function unzipBlob(blob, callback) {
zipFs.importBlob(blob, function() {
var firstEntry = zipFs.root.children[0];
firstEntry.getBlob(zip.getMimeType(firstEntry.name), callback);
}, onerror);
}
function logBlobText(blob) {
var reader = new FileReader();
reader.onload = function(e) {
console.log(e.target.result);
console.log("--------------");
};
reader.readAsText(blob);
}
zip.workerScriptsPath = "../";
blob = new Blob([TEXT_CONTENT], {
type : zip.getMimeType(FILENAME)
});
logBlobText(blob);
zipBlob(blob, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedBlob) {
logBlobText(unzippedBlob);
});
});

12
lib/zip.js/tests/test4.html Executable file
View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo base 64</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test4.js"></script>
</body>
</html>

40
lib/zip.js/tests/test4.js Executable file
View file

@ -0,0 +1,40 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var dataURI = "data:text/plain;base64," + btoa(TEXT_CONTENT);
function onerror(message) {
console.error(message);
}
function zipDataURI(dataURI, callback) {
zip.createWriter(new zip.BlobWriter("application/zip"), function(zipWriter) {
zipWriter.add(FILENAME, new zip.Data64URIReader(dataURI), function() {
zipWriter.close(callback);
});
}, onerror);
}
function unzipBlob(blob, callback) {
zip.createReader(new zip.BlobReader(blob), function(zipReader) {
zipReader.getEntries(function(entries) {
entries[0].getData(new zip.Data64URIWriter("text/plain"), function(data) {
zipReader.close();
callback(data);
});
});
}, onerror);
}
function logDataURI(dataURI) {
console.log(dataURI);
console.log("--------------");
}
zip.workerScriptsPath = "../";
logDataURI(dataURI);
zipDataURI(dataURI, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedDataURI) {
logDataURI(unzippedDataURI);
});
});

13
lib/zip.js/tests/test5.html Executable file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo filesystem API with base64</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test5.js"></script>
</body>
</html>

33
lib/zip.js/tests/test5.js Executable file
View file

@ -0,0 +1,33 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var dataURI = "data:text/plain;base64," + btoa(TEXT_CONTENT), zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipDataURI(dataURI, callback) {
zipFs.root.addData64URI(FILENAME, dataURI);
zipFs.exportData64URI(callback);
}
function unzipDataURI(dataURI, callback) {
zipFs.importData64URI(dataURI, function() {
var firstEntry = zipFs.root.children[0];
firstEntry.getData64URI("text/plain", callback, null, true);
}, onerror);
}
function logDataURI(dataURI) {
console.log(dataURI);
console.log("--------------");
}
zip.workerScriptsPath = "../";
logDataURI(dataURI);
zipDataURI(dataURI, function(zippedDataURI) {
unzipDataURI(zippedDataURI, function(unzippedDataURI) {
logDataURI(unzippedDataURI);
});
});

13
lib/zip.js/tests/test6.html Executable file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo filesystem API with base64</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test6.js"></script>
</body>
</html>

33
lib/zip.js/tests/test6.js Executable file
View file

@ -0,0 +1,33 @@
var TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
var FILENAME = "lorem.txt";
var zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipText(text, callback) {
zipFs.root.addText(FILENAME, text);
zipFs.exportBlob(callback);
}
function unzipBlob(blob, callback) {
zipFs.importBlob(blob, function() {
var firstEntry = zipFs.root.children[0];
firstEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
logText(TEXT_CONTENT);
zipText(TEXT_CONTENT, function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedText) {
logText(unzippedText);
});
});

14
lib/zip.js/tests/test7.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo HttpReader</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test7.js"></script>
</body>
</html>

18
lib/zip.js/tests/test7.js Executable file
View file

@ -0,0 +1,18 @@
var zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
zipFs.importHttpContent("lorem.zip", false, function() {
var firstEntry = zipFs.root.children[0];
firstEntry.getText(function(data) {
logText(data);
});
}, onerror);

14
lib/zip.js/tests/test8.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo FileHTTP</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test8.js"></script>
</body>
</html>

31
lib/zip.js/tests/test8.js Executable file
View file

@ -0,0 +1,31 @@
var FILENAME = "lorem.txt", URL = "lorem.txt";
var zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipText(callback) {
zipFs.root.addHttpContent(FILENAME, URL);
zipFs.exportBlob(callback);
}
function unzipBlob(blob, callback) {
zipFs.importBlob(blob, function() {
var firstEntry = zipFs.root.children[0];
firstEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
zipText(function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedText) {
logText(unzippedText);
});
});

14
lib/zip.js/tests/test9.html Executable file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Demo FileHTTP import</title>
</head>
<body>
<script type="text/javascript" src="../zip.js"></script>
<script type="text/javascript" src="../zip-fs.js"></script>
<script type="text/javascript" src="../zip-ext.js"></script>
<script type="text/javascript" src="dataview.js"></script>
<script type="text/javascript" src="test9.js"></script>
</body>
</html>

34
lib/zip.js/tests/test9.js Executable file
View file

@ -0,0 +1,34 @@
var URL = "lorem.zip";
var zipFs = new zip.fs.FS();
function onerror(message) {
console.error(message);
}
function zipImportedZip(callback) {
var directory = zipFs.root.addDirectory("import");
directory.importHttpContent(URL, false, function() {
zipFs.exportBlob(callback);
}, onerror);
}
function unzipBlob(blob, callback) {
zipFs.importBlob(blob, function() {
var directory = zipFs.root.getChildByName("import");
var firstEntry = directory.children[0];
firstEntry.getText(callback);
}, onerror);
}
function logText(text) {
console.log(text);
console.log("--------------");
}
zip.workerScriptsPath = "../";
zipImportedZip(function(zippedBlob) {
unzipBlob(zippedBlob, function(unzippedText) {
logText(unzippedText);
});
});

16
lib/zip.js/tests/util.js Executable file
View file

@ -0,0 +1,16 @@
function createTempFile(callback) {
var TMP_FILENAME = "file.tmp";
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(filesystem) {
function create() {
filesystem.root.getFile(TMP_FILENAME, {
create : true
}, function(entry) {
callback(entry);
}, onerror);
}
filesystem.root.getFile(TMP_FILENAME, null, function(entry) {
entry.remove(create, create);
}, create);
});
}