monocle-rails 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/lib/monocle/rails/version.rb +1 -1
  2. data/vendor/assets/.DS_Store +0 -0
  3. data/vendor/assets/javascripts/deflate.js +2088 -0
  4. data/vendor/assets/javascripts/inflate.js +2163 -0
  5. data/vendor/assets/javascripts/mime-types.js +1001 -0
  6. data/vendor/assets/javascripts/tests/arraybuffer.js +760 -0
  7. data/vendor/assets/javascripts/tests/base64.js +58 -0
  8. data/vendor/assets/javascripts/tests/dataview.js +212 -0
  9. data/vendor/assets/javascripts/tests/lorem.txt +1 -0
  10. data/vendor/assets/javascripts/tests/lorem.zip +0 -0
  11. data/vendor/assets/javascripts/tests/lorem2.zip +0 -0
  12. data/vendor/assets/javascripts/tests/lorem_store.zip +0 -0
  13. data/vendor/assets/javascripts/tests/test1.html +13 -0
  14. data/vendor/assets/javascripts/tests/test1.js +46 -0
  15. data/vendor/assets/javascripts/tests/test10.html +14 -0
  16. data/vendor/assets/javascripts/tests/test10.js +34 -0
  17. data/vendor/assets/javascripts/tests/test11.html +14 -0
  18. data/vendor/assets/javascripts/tests/test11.js +67 -0
  19. data/vendor/assets/javascripts/tests/test12.html +14 -0
  20. data/vendor/assets/javascripts/tests/test12.js +66 -0
  21. data/vendor/assets/javascripts/tests/test13.html +13 -0
  22. data/vendor/assets/javascripts/tests/test13.js +74 -0
  23. data/vendor/assets/javascripts/tests/test14.html +13 -0
  24. data/vendor/assets/javascripts/tests/test14.js +80 -0
  25. data/vendor/assets/javascripts/tests/test15.html +12 -0
  26. data/vendor/assets/javascripts/tests/test15.js +60 -0
  27. data/vendor/assets/javascripts/tests/test16.html +14 -0
  28. data/vendor/assets/javascripts/tests/test16.js +46 -0
  29. data/vendor/assets/javascripts/tests/test17.html +15 -0
  30. data/vendor/assets/javascripts/tests/test17.js +41 -0
  31. data/vendor/assets/javascripts/tests/test18.html +16 -0
  32. data/vendor/assets/javascripts/tests/test18.js +46 -0
  33. data/vendor/assets/javascripts/tests/test2.html +14 -0
  34. data/vendor/assets/javascripts/tests/test2.js +49 -0
  35. data/vendor/assets/javascripts/tests/test3.html +14 -0
  36. data/vendor/assets/javascripts/tests/test3.js +40 -0
  37. data/vendor/assets/javascripts/tests/test4.html +12 -0
  38. data/vendor/assets/javascripts/tests/test4.js +40 -0
  39. data/vendor/assets/javascripts/tests/test5.html +13 -0
  40. data/vendor/assets/javascripts/tests/test5.js +33 -0
  41. data/vendor/assets/javascripts/tests/test6.html +13 -0
  42. data/vendor/assets/javascripts/tests/test6.js +33 -0
  43. data/vendor/assets/javascripts/tests/test7.html +14 -0
  44. data/vendor/assets/javascripts/tests/test7.js +18 -0
  45. data/vendor/assets/javascripts/tests/test8.html +14 -0
  46. data/vendor/assets/javascripts/tests/test8.js +31 -0
  47. data/vendor/assets/javascripts/tests/test9.html +14 -0
  48. data/vendor/assets/javascripts/tests/test9.js +34 -0
  49. data/vendor/assets/javascripts/tests/util.js +16 -0
  50. data/vendor/assets/javascripts/zip-ext.js +241 -0
  51. data/vendor/assets/javascripts/zip-fs.js +538 -0
  52. data/vendor/assets/javascripts/zip.js +801 -0
  53. metadata +51 -1
@@ -0,0 +1,16 @@
1
+ function createTempFile(callback) {
2
+ var TMP_FILENAME = "file.tmp";
3
+ requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(filesystem) {
4
+ function create() {
5
+ filesystem.root.getFile(TMP_FILENAME, {
6
+ create : true
7
+ }, function(entry) {
8
+ callback(entry);
9
+ }, onerror);
10
+ }
11
+
12
+ filesystem.root.getFile(TMP_FILENAME, null, function(entry) {
13
+ entry.remove(create, create);
14
+ }, create);
15
+ });
16
+ }
@@ -0,0 +1,241 @@
1
+ /*
2
+ Copyright (c) 2013 Gildas Lormeau. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in
12
+ the documentation and/or other materials provided with the distribution.
13
+
14
+ 3. The names of the authors may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ (function() {
30
+
31
+ var ERR_HTTP_RANGE = "HTTP Range not supported.";
32
+
33
+ var Reader = zip.Reader;
34
+ var Writer = zip.Writer;
35
+
36
+ var ZipDirectoryEntry;
37
+
38
+ var appendABViewSupported;
39
+ try {
40
+ appendABViewSupported = new Blob([ new DataView(new ArrayBuffer(0)) ]).size === 0;
41
+ } catch (e) {
42
+ }
43
+
44
+ function HttpReader(url) {
45
+ var that = this;
46
+
47
+ function getData(callback, onerror) {
48
+ var request;
49
+ if (!that.data) {
50
+ request = new XMLHttpRequest();
51
+ request.addEventListener("load", function() {
52
+ if (!that.size)
53
+ that.size = Number(request.getResponseHeader("Content-Length"));
54
+ that.data = new Uint8Array(request.response);
55
+ callback();
56
+ }, false);
57
+ request.addEventListener("error", onerror, false);
58
+ request.open("GET", url);
59
+ request.responseType = "arraybuffer";
60
+ request.send();
61
+ } else
62
+ callback();
63
+ }
64
+
65
+ function init(callback, onerror) {
66
+ var request = new XMLHttpRequest();
67
+ request.addEventListener("load", function() {
68
+ that.size = Number(request.getResponseHeader("Content-Length"));
69
+ callback();
70
+ }, false);
71
+ request.addEventListener("error", onerror, false);
72
+ request.open("HEAD", url);
73
+ request.send();
74
+ }
75
+
76
+ function readUint8Array(index, length, callback, onerror) {
77
+ getData(function() {
78
+ callback(new Uint8Array(that.data.subarray(index, index + length)));
79
+ }, onerror);
80
+ }
81
+
82
+ that.size = 0;
83
+ that.init = init;
84
+ that.readUint8Array = readUint8Array;
85
+ }
86
+ HttpReader.prototype = new Reader();
87
+ HttpReader.prototype.constructor = HttpReader;
88
+
89
+ function HttpRangeReader(url) {
90
+ var that = this;
91
+
92
+ function init(callback, onerror) {
93
+ var request = new XMLHttpRequest();
94
+ request.addEventListener("load", function() {
95
+ that.size = Number(request.getResponseHeader("Content-Length"));
96
+ if (request.getResponseHeader("Accept-Ranges") == "bytes")
97
+ callback();
98
+ else
99
+ onerror(ERR_HTTP_RANGE);
100
+ }, false);
101
+ request.addEventListener("error", onerror, false);
102
+ request.open("HEAD", url);
103
+ request.send();
104
+ }
105
+
106
+ function readArrayBuffer(index, length, callback, onerror) {
107
+ var request = new XMLHttpRequest();
108
+ request.open("GET", url);
109
+ request.responseType = "arraybuffer";
110
+ request.setRequestHeader("Range", "bytes=" + index + "-" + (index + length - 1));
111
+ request.addEventListener("load", function() {
112
+ callback(request.response);
113
+ }, false);
114
+ request.addEventListener("error", onerror, false);
115
+ request.send();
116
+ }
117
+
118
+ function readUint8Array(index, length, callback, onerror) {
119
+ readArrayBuffer(index, length, function(arraybuffer) {
120
+ callback(new Uint8Array(arraybuffer));
121
+ }, onerror);
122
+ }
123
+
124
+ that.size = 0;
125
+ that.init = init;
126
+ that.readUint8Array = readUint8Array;
127
+ }
128
+ HttpRangeReader.prototype = new Reader();
129
+ HttpRangeReader.prototype.constructor = HttpRangeReader;
130
+
131
+ function ArrayBufferReader(arrayBuffer) {
132
+ var that = this;
133
+
134
+ function init(callback, onerror) {
135
+ that.size = arrayBuffer.byteLength;
136
+ callback();
137
+ }
138
+
139
+ function readUint8Array(index, length, callback, onerror) {
140
+ callback(new Uint8Array(arrayBuffer.slice(index, index + length)));
141
+ }
142
+
143
+ that.size = 0;
144
+ that.init = init;
145
+ that.readUint8Array = readUint8Array;
146
+ }
147
+ ArrayBufferReader.prototype = new Reader();
148
+ ArrayBufferReader.prototype.constructor = ArrayBufferReader;
149
+
150
+ function ArrayBufferWriter() {
151
+ var array, that = this;
152
+
153
+ function init(callback, onerror) {
154
+ array = new Uint8Array();
155
+ callback();
156
+ }
157
+
158
+ function writeUint8Array(arr, callback, onerror) {
159
+ var tmpArray = new Uint8Array(array.length + arr.length);
160
+ tmpArray.set(array);
161
+ tmpArray.set(arr, array.length);
162
+ array = tmpArray;
163
+ callback();
164
+ }
165
+
166
+ function getData(callback) {
167
+ callback(array.buffer);
168
+ }
169
+
170
+ that.init = init;
171
+ that.writeUint8Array = writeUint8Array;
172
+ that.getData = getData;
173
+ }
174
+ ArrayBufferWriter.prototype = new Writer();
175
+ ArrayBufferWriter.prototype.constructor = ArrayBufferWriter;
176
+
177
+ function FileWriter(fileEntry, contentType) {
178
+ var writer, that = this;
179
+
180
+ function init(callback, onerror) {
181
+ fileEntry.createWriter(function(fileWriter) {
182
+ writer = fileWriter;
183
+ callback();
184
+ }, onerror);
185
+ }
186
+
187
+ function writeUint8Array(array, callback, onerror) {
188
+ var blob = new Blob([ appendABViewSupported ? array : array.buffer ], {
189
+ type : contentType
190
+ });
191
+ writer.onwrite = function() {
192
+ writer.onwrite = null;
193
+ callback();
194
+ };
195
+ writer.onerror = onerror;
196
+ writer.write(blob);
197
+ }
198
+
199
+ function getData(callback) {
200
+ fileEntry.file(callback);
201
+ }
202
+
203
+ that.init = init;
204
+ that.writeUint8Array = writeUint8Array;
205
+ that.getData = getData;
206
+ }
207
+ FileWriter.prototype = new Writer();
208
+ FileWriter.prototype.constructor = FileWriter;
209
+
210
+ zip.FileWriter = FileWriter;
211
+ zip.HttpReader = HttpReader;
212
+ zip.HttpRangeReader = HttpRangeReader;
213
+ zip.ArrayBufferReader = ArrayBufferReader;
214
+ zip.ArrayBufferWriter = ArrayBufferWriter;
215
+
216
+ if (zip.fs) {
217
+ ZipDirectoryEntry = zip.fs.ZipDirectoryEntry;
218
+ ZipDirectoryEntry.prototype.addHttpContent = function(name, URL, useRangeHeader) {
219
+ function addChild(parent, name, params, directory) {
220
+ if (parent.directory)
221
+ return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new zip.fs.ZipFileEntry(parent.fs, name, params, parent);
222
+ else
223
+ throw "Parent entry is not a directory.";
224
+ }
225
+
226
+ return addChild(this, name, {
227
+ data : URL,
228
+ Reader : useRangeHeader ? HttpRangeReader : HttpReader
229
+ });
230
+ };
231
+ ZipDirectoryEntry.prototype.importHttpContent = function(URL, useRangeHeader, onend, onerror) {
232
+ this.importZip(useRangeHeader ? new HttpRangeReader(URL) : new HttpReader(URL), onend, onerror);
233
+ };
234
+ zip.fs.FS.prototype.importHttpContent = function(URL, useRangeHeader, onend, onerror) {
235
+ this.entries = [];
236
+ this.root = new ZipDirectoryEntry(this);
237
+ this.root.importHttpContent(URL, useRangeHeader, onend, onerror);
238
+ };
239
+ }
240
+
241
+ })();
@@ -0,0 +1,538 @@
1
+ /*
2
+ Copyright (c) 2013 Gildas Lormeau. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in
12
+ the documentation and/or other materials provided with the distribution.
13
+
14
+ 3. The names of the authors may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ (function() {
30
+
31
+ var CHUNK_SIZE = 512 * 1024;
32
+
33
+ var TextWriter = zip.TextWriter, //
34
+ BlobWriter = zip.BlobWriter, //
35
+ Data64URIWriter = zip.Data64URIWriter, //
36
+ Reader = zip.Reader, //
37
+ TextReader = zip.TextReader, //
38
+ BlobReader = zip.BlobReader, //
39
+ Data64URIReader = zip.Data64URIReader, //
40
+ createReader = zip.createReader, //
41
+ createWriter = zip.createWriter;
42
+
43
+ function ZipBlobReader(entry) {
44
+ var that = this, blobReader;
45
+
46
+ function init(callback) {
47
+ this.size = entry.uncompressedSize;
48
+ callback();
49
+ }
50
+
51
+ function getData(callback) {
52
+ if (that.data)
53
+ callback();
54
+ else
55
+ entry.getData(new BlobWriter(), function(data) {
56
+ that.data = data;
57
+ blobReader = new BlobReader(data);
58
+ callback();
59
+ }, null, that.checkCrc32);
60
+ }
61
+
62
+ function readUint8Array(index, length, callback, onerror) {
63
+ getData(function() {
64
+ blobReader.readUint8Array(index, length, callback, onerror);
65
+ }, onerror);
66
+ }
67
+
68
+ that.size = 0;
69
+ that.init = init;
70
+ that.readUint8Array = readUint8Array;
71
+ }
72
+ ZipBlobReader.prototype = new Reader();
73
+ ZipBlobReader.prototype.constructor = ZipBlobReader;
74
+ ZipBlobReader.prototype.checkCrc32 = false;
75
+
76
+ function getTotalSize(entry) {
77
+ var size = 0;
78
+
79
+ function process(entry) {
80
+ size += entry.uncompressedSize || 0;
81
+ entry.children.forEach(process);
82
+ }
83
+
84
+ process(entry);
85
+ return size;
86
+ }
87
+
88
+ function initReaders(entry, onend, onerror) {
89
+ var index = 0;
90
+
91
+ function next() {
92
+ index++;
93
+ if (index < entry.children.length)
94
+ process(entry.children[index]);
95
+ else
96
+ onend();
97
+ }
98
+
99
+ function process(child) {
100
+ if (child.directory)
101
+ initReaders(child, next, onerror);
102
+ else {
103
+ child.reader = new child.Reader(child.data, onerror);
104
+ child.reader.init(function() {
105
+ child.uncompressedSize = child.reader.size;
106
+ next();
107
+ });
108
+ }
109
+ }
110
+
111
+ if (entry.children.length)
112
+ process(entry.children[index]);
113
+ else
114
+ onend();
115
+ }
116
+
117
+ function detach(entry) {
118
+ var children = entry.parent.children;
119
+ children.forEach(function(child, index) {
120
+ if (child.id == entry.id)
121
+ children.splice(index, 1);
122
+ });
123
+ }
124
+
125
+ function exportZip(zipWriter, entry, onend, onprogress, totalSize) {
126
+ var currentIndex = 0;
127
+
128
+ function process(zipWriter, entry, onend, onprogress, totalSize) {
129
+ var childIndex = 0;
130
+
131
+ function exportChild() {
132
+ var child = entry.children[childIndex];
133
+ if (child)
134
+ zipWriter.add(child.getFullname(), child.reader, function() {
135
+ currentIndex += child.uncompressedSize || 0;
136
+ process(zipWriter, child, function() {
137
+ childIndex++;
138
+ exportChild();
139
+ }, onprogress, totalSize);
140
+ }, function(index) {
141
+ if (onprogress)
142
+ onprogress(currentIndex + index, totalSize);
143
+ }, {
144
+ directory : child.directory,
145
+ version : child.zipVersion
146
+ });
147
+ else
148
+ onend();
149
+ }
150
+
151
+ exportChild();
152
+ }
153
+
154
+ process(zipWriter, entry, onend, onprogress, totalSize);
155
+ }
156
+
157
+ function addFileEntry(zipEntry, fileEntry, onend, onerror) {
158
+ function getChildren(fileEntry, callback) {
159
+ if (fileEntry.isDirectory)
160
+ fileEntry.createReader().readEntries(callback);
161
+ if (fileEntry.isFile)
162
+ callback([]);
163
+ }
164
+
165
+ function process(zipEntry, fileEntry, onend) {
166
+ getChildren(fileEntry, function(children) {
167
+ var childIndex = 0;
168
+
169
+ function addChild(child) {
170
+ function nextChild(childFileEntry) {
171
+ process(childFileEntry, child, function() {
172
+ childIndex++;
173
+ processChild();
174
+ });
175
+ }
176
+
177
+ if (child.isDirectory)
178
+ nextChild(zipEntry.addDirectory(child.name));
179
+ if (child.isFile)
180
+ child.file(function(file) {
181
+ var childZipEntry = zipEntry.addBlob(child.name, file);
182
+ childZipEntry.uncompressedSize = file.size;
183
+ nextChild(childZipEntry);
184
+ }, onerror);
185
+ }
186
+
187
+ function processChild() {
188
+ var child = children[childIndex];
189
+ if (child)
190
+ addChild(child);
191
+ else
192
+ onend();
193
+ }
194
+
195
+ processChild();
196
+ });
197
+ }
198
+
199
+ if (fileEntry.isDirectory)
200
+ process(zipEntry, fileEntry, onend);
201
+ else
202
+ fileEntry.file(function(file) {
203
+ zipEntry.addBlob(fileEntry.name, file);
204
+ onend();
205
+ }, onerror);
206
+ }
207
+
208
+ function getFileEntry(fileEntry, entry, onend, onprogress, onerror, totalSize, checkCrc32) {
209
+ var currentIndex = 0;
210
+
211
+ function process(fileEntry, entry, onend, onprogress, onerror, totalSize) {
212
+ var childIndex = 0;
213
+
214
+ function addChild(child) {
215
+ function nextChild(childFileEntry) {
216
+ currentIndex += child.uncompressedSize || 0;
217
+ process(childFileEntry, child, function() {
218
+ childIndex++;
219
+ processChild();
220
+ }, onprogress, onerror, totalSize);
221
+ }
222
+
223
+ if (child.directory)
224
+ fileEntry.getDirectory(child.name, {
225
+ create : true
226
+ }, nextChild, onerror);
227
+ else
228
+ fileEntry.getFile(child.name, {
229
+ create : true
230
+ }, function(file) {
231
+ child.getData(new zip.FileWriter(file, zip.getMimeType(child.name)), nextChild, function(index) {
232
+ if (onprogress)
233
+ onprogress(currentIndex + index, totalSize);
234
+ }, checkCrc32);
235
+ }, onerror);
236
+ }
237
+
238
+ function processChild() {
239
+ var child = entry.children[childIndex];
240
+ if (child)
241
+ addChild(child);
242
+ else
243
+ onend();
244
+ }
245
+
246
+ processChild();
247
+ }
248
+
249
+ if (entry.directory)
250
+ process(fileEntry, entry, onend, onprogress, onerror, totalSize);
251
+ else
252
+ entry.getData(new zip.FileWriter(fileEntry, zip.getMimeType(entry.name)), onend, onprogress, checkCrc32);
253
+ }
254
+
255
+ function resetFS(fs) {
256
+ fs.entries = [];
257
+ fs.root = new ZipDirectoryEntry(fs);
258
+ }
259
+
260
+ function bufferedCopy(reader, writer, onend, onprogress, onerror) {
261
+ var chunkIndex = 0;
262
+
263
+ function stepCopy() {
264
+ var index = chunkIndex * CHUNK_SIZE;
265
+ if (onprogress)
266
+ onprogress(index, reader.size);
267
+ if (index < reader.size)
268
+ reader.readUint8Array(index, Math.min(CHUNK_SIZE, reader.size - index), function(array) {
269
+ writer.writeUint8Array(new Uint8Array(array), function() {
270
+ chunkIndex++;
271
+ stepCopy();
272
+ });
273
+ }, onerror);
274
+ else
275
+ writer.getData(onend);
276
+ }
277
+
278
+ stepCopy();
279
+ }
280
+
281
+ function getEntryData(writer, onend, onprogress, onerror) {
282
+ var that = this;
283
+ if (!writer || (writer.constructor == that.Writer && that.data))
284
+ onend(that.data);
285
+ else {
286
+ if (!that.reader)
287
+ that.reader = new that.Reader(that.data, onerror);
288
+ that.reader.init(function() {
289
+ writer.init(function() {
290
+ bufferedCopy(that.reader, writer, onend, onprogress, onerror);
291
+ }, onerror);
292
+ });
293
+ }
294
+ }
295
+
296
+ function addChild(parent, name, params, directory) {
297
+ if (parent.directory)
298
+ return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
299
+ else
300
+ throw "Parent entry is not a directory.";
301
+ }
302
+
303
+ function ZipEntry() {
304
+ }
305
+
306
+ ZipEntry.prototype = {
307
+ init : function(fs, name, params, parent) {
308
+ var that = this;
309
+ if (fs.root && parent && parent.getChildByName(name))
310
+ throw "Entry filename already exists.";
311
+ if (!params)
312
+ params = {};
313
+ that.fs = fs;
314
+ that.name = name;
315
+ that.id = fs.entries.length;
316
+ that.parent = parent;
317
+ that.children = [];
318
+ that.zipVersion = params.zipVersion || 0x14;
319
+ that.uncompressedSize = 0;
320
+ fs.entries.push(that);
321
+ if (parent)
322
+ that.parent.children.push(that);
323
+ },
324
+ getFileEntry : function(fileEntry, onend, onprogress, onerror, checkCrc32) {
325
+ var that = this;
326
+ initReaders(that, function() {
327
+ getFileEntry(fileEntry, that, onend, onprogress, onerror, getTotalSize(that), checkCrc32);
328
+ }, onerror);
329
+ },
330
+ moveTo : function(target) {
331
+ var that = this;
332
+ if (target.directory) {
333
+ if (!target.isDescendantOf(that)) {
334
+ if (that != target) {
335
+ if (target.getChildByName(that.name))
336
+ throw "Entry filename already exists.";
337
+ detach(that);
338
+ that.parent = target;
339
+ target.children.push(that);
340
+ }
341
+ } else
342
+ throw "Entry is a ancestor of target entry.";
343
+ } else
344
+ throw "Target entry is not a directory.";
345
+ },
346
+ getFullname : function() {
347
+ var that = this, fullname = that.name, entry = that.parent;
348
+ while (entry) {
349
+ fullname = (entry.name ? entry.name + "/" : "") + fullname;
350
+ entry = entry.parent;
351
+ }
352
+ return fullname;
353
+ },
354
+ isDescendantOf : function(ancestor) {
355
+ var entry = this.parent;
356
+ while (entry && entry.id != ancestor.id)
357
+ entry = entry.parent;
358
+ return !!entry;
359
+ }
360
+ };
361
+ ZipEntry.prototype.constructor = ZipEntry;
362
+
363
+ var ZipFileEntryProto;
364
+
365
+ function ZipFileEntry(fs, name, params, parent) {
366
+ var that = this;
367
+ ZipEntry.prototype.init.call(that, fs, name, params, parent);
368
+ that.Reader = params.Reader;
369
+ that.Writer = params.Writer;
370
+ that.data = params.data;
371
+ that.getData = params.getData || getEntryData;
372
+ }
373
+
374
+ ZipFileEntry.prototype = ZipFileEntryProto = new ZipEntry();
375
+ ZipFileEntryProto.constructor = ZipFileEntry;
376
+ ZipFileEntryProto.getText = function(onend, onprogress, checkCrc32, encoding) {
377
+ this.getData(new TextWriter(encoding), onend, onprogress, checkCrc32);
378
+ };
379
+ ZipFileEntryProto.getBlob = function(mimeType, onend, onprogress, checkCrc32) {
380
+ this.getData(new BlobWriter(mimeType), onend, onprogress, checkCrc32);
381
+ };
382
+ ZipFileEntryProto.getData64URI = function(mimeType, onend, onprogress, checkCrc32) {
383
+ this.getData(new Data64URIWriter(mimeType), onend, onprogress, checkCrc32);
384
+ };
385
+
386
+ var ZipDirectoryEntryProto;
387
+
388
+ function ZipDirectoryEntry(fs, name, params, parent) {
389
+ var that = this;
390
+ ZipEntry.prototype.init.call(that, fs, name, params, parent);
391
+ that.directory = true;
392
+ }
393
+
394
+ ZipDirectoryEntry.prototype = ZipDirectoryEntryProto = new ZipEntry();
395
+ ZipDirectoryEntryProto.constructor = ZipDirectoryEntry;
396
+ ZipDirectoryEntryProto.addDirectory = function(name) {
397
+ return addChild(this, name, null, true);
398
+ };
399
+ ZipDirectoryEntryProto.addText = function(name, text) {
400
+ return addChild(this, name, {
401
+ data : text,
402
+ Reader : TextReader,
403
+ Writer : TextWriter
404
+ });
405
+ };
406
+ ZipDirectoryEntryProto.addBlob = function(name, blob) {
407
+ return addChild(this, name, {
408
+ data : blob,
409
+ Reader : BlobReader,
410
+ Writer : BlobWriter
411
+ });
412
+ };
413
+ ZipDirectoryEntryProto.addData64URI = function(name, dataURI) {
414
+ return addChild(this, name, {
415
+ data : dataURI,
416
+ Reader : Data64URIReader,
417
+ Writer : Data64URIWriter
418
+ });
419
+ };
420
+ ZipDirectoryEntryProto.addFileEntry = function(fileEntry, onend, onerror) {
421
+ addFileEntry(this, fileEntry, onend, onerror);
422
+ };
423
+ ZipDirectoryEntryProto.addData = function(name, params) {
424
+ return addChild(this, name, params);
425
+ };
426
+ ZipDirectoryEntryProto.importBlob = function(blob, onend, onerror) {
427
+ this.importZip(new BlobReader(blob), onend, onerror);
428
+ };
429
+ ZipDirectoryEntryProto.importText = function(text, onend, onerror) {
430
+ this.importZip(new TextReader(text), onend, onerror);
431
+ };
432
+ ZipDirectoryEntryProto.importData64URI = function(dataURI, onend, onerror) {
433
+ this.importZip(new Data64URIReader(dataURI), onend, onerror);
434
+ };
435
+ ZipDirectoryEntryProto.exportBlob = function(onend, onprogress, onerror) {
436
+ this.exportZip(new BlobWriter("application/zip"), onend, onprogress, onerror);
437
+ };
438
+ ZipDirectoryEntryProto.exportText = function(onend, onprogress, onerror) {
439
+ this.exportZip(new TextWriter(), onend, onprogress, onerror);
440
+ };
441
+ ZipDirectoryEntryProto.exportFileEntry = function(fileEntry, onend, onprogress, onerror) {
442
+ this.exportZip(new zip.FileWriter(fileEntry, "application/zip"), onend, onprogress, onerror);
443
+ };
444
+ ZipDirectoryEntryProto.exportData64URI = function(onend, onprogress, onerror) {
445
+ this.exportZip(new Data64URIWriter("application/zip"), onend, onprogress, onerror);
446
+ };
447
+ ZipDirectoryEntryProto.importZip = function(reader, onend, onerror) {
448
+ var that = this;
449
+ createReader(reader, function(zipReader) {
450
+ zipReader.getEntries(function(entries) {
451
+ entries.forEach(function(entry) {
452
+ var parent = that, path = entry.filename.split("/"), name = path.pop();
453
+ path.forEach(function(pathPart) {
454
+ parent = parent.getChildByName(pathPart) || new ZipDirectoryEntry(that.fs, pathPart, null, parent);
455
+ });
456
+ if (!entry.directory)
457
+ addChild(parent, name, {
458
+ data : entry,
459
+ Reader : ZipBlobReader
460
+ });
461
+ });
462
+ onend();
463
+ });
464
+ }, onerror);
465
+ };
466
+ ZipDirectoryEntryProto.exportZip = function(writer, onend, onprogress, onerror) {
467
+ var that = this;
468
+ initReaders(that, function() {
469
+ createWriter(writer, function(zipWriter) {
470
+ exportZip(zipWriter, that, function() {
471
+ zipWriter.close(onend);
472
+ }, onprogress, getTotalSize(that));
473
+ }, onerror);
474
+ }, onerror);
475
+ };
476
+ ZipDirectoryEntryProto.getChildByName = function(name) {
477
+ var childIndex, child, that = this;
478
+ for (childIndex = 0; childIndex < that.children.length; childIndex++) {
479
+ child = that.children[childIndex];
480
+ if (child.name == name)
481
+ return child;
482
+ }
483
+ };
484
+
485
+ function FS() {
486
+ resetFS(this);
487
+ }
488
+ FS.prototype = {
489
+ remove : function(entry) {
490
+ detach(entry);
491
+ this.entries[entry.id] = null;
492
+ },
493
+ find : function(fullname) {
494
+ var index, path = fullname.split("/"), node = this.root;
495
+ for (index = 0; node && index < path.length; index++)
496
+ node = node.getChildByName(path[index]);
497
+ return node;
498
+ },
499
+ getById : function(id) {
500
+ return this.entries[id];
501
+ },
502
+ importBlob : function(blob, onend, onerror) {
503
+ resetFS(this);
504
+ this.root.importBlob(blob, onend, onerror);
505
+ },
506
+ importText : function(text, onend, onerror) {
507
+ resetFS(this);
508
+ this.root.importText(text, onend, onerror);
509
+ },
510
+ importData64URI : function(dataURI, onend, onerror) {
511
+ resetFS(this);
512
+ this.root.importData64URI(dataURI, onend, onerror);
513
+ },
514
+ exportBlob : function(onend, onprogress, onerror) {
515
+ this.root.exportBlob(onend, onprogress, onerror);
516
+ },
517
+ exportText : function(onend, onprogress, onerror) {
518
+ this.root.exportText(onend, onprogress, onerror);
519
+ },
520
+ exportFileEntry : function(fileEntry, onend, onprogress, onerror) {
521
+ this.root.exportFileEntry(fileEntry, onend, onprogress, onerror);
522
+ },
523
+ exportData64URI : function(onend, onprogress, onerror) {
524
+ this.root.exportData64URI(onend, onprogress, onerror);
525
+ }
526
+ };
527
+
528
+ zip.fs = {
529
+ FS : FS,
530
+ ZipDirectoryEntry : ZipDirectoryEntry,
531
+ ZipFileEntry : ZipFileEntry
532
+ };
533
+
534
+ zip.getMimeType = function() {
535
+ return "application/octet-stream";
536
+ };
537
+
538
+ })();