| 
									
										
										
										
											2015-04-02 20:32:22 +00:00
										 |  |  | function firstbyte(f,o) { | 
					
						
							|  |  |  | 	switch((o||{}).type || "base64") { | 
					
						
							|  |  |  | 		case 'buffer': return f[0]; | 
					
						
							|  |  |  | 		case 'base64': return Base64.decode(f.substr(0,12)).charCodeAt(0); | 
					
						
							|  |  |  | 		case 'binary': return f.charCodeAt(0); | 
					
						
							|  |  |  | 		case 'array': return f[0]; | 
					
						
							|  |  |  | 		default: throw new Error("Unrecognized type " + o.type); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function read_zip(data, opts) { | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	var zip, d = data; | 
					
						
							| 
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 |  |  | 	var o = opts||{}; | 
					
						
							| 
									
										
										
										
											2014-07-28 13:22:32 +00:00
										 |  |  | 	if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64"; | 
					
						
							| 
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 |  |  | 	switch(o.type) { | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 		case "base64": zip = new jszip(d, { base64:true }); break; | 
					
						
							| 
									
										
										
										
											2015-04-02 20:32:22 +00:00
										 |  |  | 		case "binary": case "array": zip = new jszip(d, { base64:false }); break; | 
					
						
							| 
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 |  |  | 		case "buffer": zip = new jszip(d); break; | 
					
						
							|  |  |  | 		case "file": zip=new jszip(d=_fs.readFileSync(data)); break; | 
					
						
							|  |  |  | 		default: throw new Error("Unrecognized type " + o.type); | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 |  |  | 	return parse_zip(zip, o); | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:32:22 +00:00
										 |  |  | function readSync(data, opts) { | 
					
						
							|  |  |  | 	var zip, d = data, isfile = false, n; | 
					
						
							|  |  |  | 	var o = opts||{}; | 
					
						
							|  |  |  | 	if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64"; | 
					
						
							|  |  |  | 	if(o.type == "file") { isfile = true; o.type = "buffer"; d = _fs.readFileSync(data); } | 
					
						
							|  |  |  | 	switch((n = firstbyte(d, o))) { | 
					
						
							|  |  |  | 		case 0xD0: | 
					
						
							|  |  |  | 			if(isfile) o.type = "file"; | 
					
						
							|  |  |  | 			return parse_xlscfb(CFB.read(data, o), o); | 
					
						
							|  |  |  | 		case 0x09: return parse_xlscfb(s2a(o.type === 'base64' ? Base64.decode(data) : data), o); | 
					
						
							|  |  |  | 		case 0x3C: return parse_xlml(d, o); | 
					
						
							|  |  |  | 		case 0x50: | 
					
						
							|  |  |  | 			if(isfile) o.type = "file"; | 
					
						
							|  |  |  | 			return read_zip(data, opts); | 
					
						
							|  |  |  | 		default: throw new Error("Unsupported file " + n); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-16 00:33:34 +00:00
										 |  |  | function readFileSync(data, opts) { | 
					
						
							|  |  |  | 	var o = opts||{}; o.type = 'file'; | 
					
						
							| 
									
										
										
										
											2014-01-28 16:38:02 +00:00
										 |  |  | 	return readSync(data, o); | 
					
						
							|  |  |  | } |