| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | function getdatastr(data)/*:?string*/ { | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	if(!data) return null; | 
					
						
							| 
									
										
										
										
											2017-02-24 10:33:01 +00:00
										 |  |  | 	if(data.data) return debom(data.data); | 
					
						
							|  |  |  | 	if(data.asNodeBuffer && has_buf) return debom(data.asNodeBuffer().toString('binary')); | 
					
						
							|  |  |  | 	if(data.asBinary) return debom(data.asBinary()); | 
					
						
							|  |  |  | 	if(data._data && data._data.getContent) return debom(cc2str(Array.prototype.slice.call(data._data.getContent(),0))); | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | 	return null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function getdatabin(data) { | 
					
						
							|  |  |  | 	if(!data) return null; | 
					
						
							|  |  |  | 	if(data.data) return char_codes(data.data); | 
					
						
							|  |  |  | 	if(data.asNodeBuffer && has_buf) return data.asNodeBuffer(); | 
					
						
							| 
									
										
										
										
											2017-02-22 06:57:59 +00:00
										 |  |  | 	if(data._data && data._data.getContent) { | 
					
						
							|  |  |  | 		var o = data._data.getContent(); | 
					
						
							|  |  |  | 		if(typeof o == "string") return str2cc(o); | 
					
						
							|  |  |  | 		return Array.prototype.slice.call(o); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	return null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-22 06:57:59 +00:00
										 |  |  | function getdata(data) { return (data && data.name.slice(-4) === ".bin") ? getdatabin(data) : getdatastr(data); } | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 10:33:01 +00:00
										 |  |  | /* Part 2 Section 10.1.2 "Mapping Content Types" Names are case-insensitive */ | 
					
						
							| 
									
										
										
										
											2017-03-10 01:09:18 +00:00
										 |  |  | /* OASIS does not comment on filename case sensitivity */ | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | function safegetzipfile(zip, file/*:string*/) { | 
					
						
							| 
									
										
										
										
											2017-02-24 10:33:01 +00:00
										 |  |  | 	var k = keys(zip.files); | 
					
						
							|  |  |  | 	var f = file.toLowerCase(), g = f.replace(/\//g,'\\'); | 
					
						
							|  |  |  | 	for(var i=0; i<k.length; ++i) { | 
					
						
							|  |  |  | 		var n = k[i].toLowerCase(); | 
					
						
							|  |  |  | 		if(f == n || g == n) return zip.files[k[i]]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-10 02:22:38 +00:00
										 |  |  | 	return null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | function getzipfile(zip, file/*:string*/) { | 
					
						
							| 
									
										
										
										
											2014-10-10 02:22:38 +00:00
										 |  |  | 	var o = safegetzipfile(zip, file); | 
					
						
							|  |  |  | 	if(o == null) throw new Error("Cannot find file " + file + " in zip"); | 
					
						
							|  |  |  | 	return o; | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | function getzipdata(zip, file/*:string*/, safe/*:?boolean*/) { | 
					
						
							| 
									
										
										
										
											2014-02-15 05:08:18 +00:00
										 |  |  | 	if(!safe) return getdata(getzipfile(zip, file)); | 
					
						
							|  |  |  | 	if(!file) return null; | 
					
						
							|  |  |  | 	try { return getzipdata(zip, file); } catch(e) { return null; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | function getzipstr(zip, file/*:string*/, safe/*:?boolean*/)/*:?string*/ { | 
					
						
							|  |  |  | 	if(!safe) return getdatastr(getzipfile(zip, file)); | 
					
						
							|  |  |  | 	if(!file) return null; | 
					
						
							|  |  |  | 	try { return getzipstr(zip, file); } catch(e) { return null; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | var _fs, jszip; | 
					
						
							| 
									
										
										
										
											2017-02-10 19:23:01 +00:00
										 |  |  | /*:: declare var JSZip:any; */ | 
					
						
							| 
									
										
										
										
											2017-05-09 18:07:57 +00:00
										 |  |  | /*global JSZip:true */ | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | if(typeof JSZip !== 'undefined') jszip = JSZip; | 
					
						
							|  |  |  | if (typeof exports !== 'undefined') { | 
					
						
							|  |  |  | 	if (typeof module !== 'undefined' && module.exports) { | 
					
						
							| 
									
										
										
										
											2017-03-05 00:56:31 +00:00
										 |  |  | 		if(typeof jszip === 'undefined') jszip = require('./jszip.js'); | 
					
						
							|  |  |  | 		_fs = require('fs'); | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-27 21:35:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | function resolve_path(path/*:string*/, base/*:string*/)/*:string*/ { | 
					
						
							|  |  |  | 	var result = base.split('/'); | 
					
						
							|  |  |  | 	if(base.slice(-1) != "/") result.pop(); // folder path
 | 
					
						
							|  |  |  | 	var target = path.split('/'); | 
					
						
							|  |  |  | 	while (target.length !== 0) { | 
					
						
							|  |  |  | 		var step = target.shift(); | 
					
						
							|  |  |  | 		if (step === '..') result.pop(); | 
					
						
							|  |  |  | 		else if (step !== '.') result.push(step); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return result.join('/'); | 
					
						
							|  |  |  | } |