1 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
3 * A Blob implementation.
6 * By Eli Grey, http://eligrey.com
7 * By Devin Samarin, https://github.com/dsamarin
9 * See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
12 /*global self, unescape */
13 /*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
16 /*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
21 view.URL = view.URL || view.webkitURL;
23 if (view.Blob && view.URL) {
30 // Internally we use a BlobBuilder implementation to base Blob off of
31 // in order to support older browsers that only have BlobBuilder
32 var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
34 get_class = function(object) {
35 return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
37 , FakeBlobBuilder = function BlobBuilder() {
40 , FakeBlob = function Blob(data, type, encoding) {
42 this.size = data.length;
44 this.encoding = encoding;
46 , FBB_proto = FakeBlobBuilder.prototype
47 , FB_proto = FakeBlob.prototype
48 , FileReaderSync = view.FileReaderSync
49 , FileException = function(type) {
50 this.code = this[this.name = type];
53 "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
54 + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
56 , file_ex_code = file_ex_codes.length
57 , real_URL = view.URL || view.webkitURL || view
58 , real_create_object_URL = real_URL.createObjectURL
59 , real_revoke_object_URL = real_URL.revokeObjectURL
64 , ArrayBuffer = view.ArrayBuffer
65 , Uint8Array = view.Uint8Array
67 , origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/
69 FakeBlob.fake = FB_proto.fake = true;
70 while (file_ex_code--) {
71 FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
74 if (!real_URL.createObjectURL) {
75 URL = view.URL = function(uri) {
77 uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
81 if (!("origin" in uri_info)) {
82 if (uri_info.protocol.toLowerCase() === "data:") {
83 uri_info.origin = null;
85 uri_origin = uri.match(origin);
86 uri_info.origin = uri_origin && uri_origin[1];
92 URL.createObjectURL = function(blob) {
98 type = "application/octet-stream";
100 if (blob instanceof FakeBlob) {
101 data_URI_header = "data:" + type;
102 if (blob.encoding === "base64") {
103 return data_URI_header + ";base64," + blob.data;
104 } else if (blob.encoding === "URI") {
105 return data_URI_header + "," + decodeURIComponent(blob.data);
107 return data_URI_header + ";base64," + btoa(blob.data);
109 return data_URI_header + "," + encodeURIComponent(blob.data);
111 } else if (real_create_object_URL) {
112 return real_create_object_URL.call(real_URL, blob);
115 URL.revokeObjectURL = function(object_URL) {
116 if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
117 real_revoke_object_URL.call(real_URL, object_URL);
120 FBB_proto.append = function(data/*, endings*/) {
122 // decode data to a binary string
123 if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
126 , buf = new Uint8Array(data)
128 , buf_len = buf.length
130 for (; i < buf_len; i++) {
131 str += String.fromCharCode(buf[i]);
134 } else if (get_class(data) === "Blob" || get_class(data) === "File") {
135 if (FileReaderSync) {
136 var fr = new FileReaderSync;
137 bb.push(fr.readAsBinaryString(data));
139 // async FileReader won't work as BlobBuilder is sync
140 throw new FileException("NOT_READABLE_ERR");
142 } else if (data instanceof FakeBlob) {
143 if (data.encoding === "base64" && atob) {
144 bb.push(atob(data.data));
145 } else if (data.encoding === "URI") {
146 bb.push(decodeURIComponent(data.data));
147 } else if (data.encoding === "raw") {
151 if (typeof data !== "string") {
152 data += ""; // convert unsupported types to strings
154 // decode UTF-16 to binary string
155 bb.push(unescape(encodeURIComponent(data)));
158 FBB_proto.getBlob = function(type) {
159 if (!arguments.length) {
162 return new FakeBlob(this.data.join(""), type, "raw");
164 FBB_proto.toString = function() {
165 return "[object BlobBuilder]";
167 FB_proto.slice = function(start, end, type) {
168 var args = arguments.length;
173 this.data.slice(start, args > 1 ? end : this.data.length)
178 FB_proto.toString = function() {
179 return "[object Blob]";
181 FB_proto.close = function() {
185 return FakeBlobBuilder;
188 view.Blob = function(blobParts, options) {
189 var type = options ? (options.type || "") : "";
190 var builder = new BlobBuilder();
192 for (var i = 0, len = blobParts.length; i < len; i++) {
193 if (Uint8Array && blobParts[i] instanceof Uint8Array) {
194 builder.append(blobParts[i].buffer);
197 builder.append(blobParts[i]);
201 var blob = builder.getBlob(type);
202 if (!blob.slice && blob.webkitSlice) {
203 blob.slice = blob.webkitSlice;
208 var getPrototypeOf = Object.getPrototypeOf || function(object) {
209 return object.__proto__;
211 view.Blob.prototype = getPrototypeOf(new view.Blob());
212 }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
214 },{}],2:[function(require,module,exports){
216 * A saveAs() FileSaver implementation.
219 * By Eli Grey, http://eligrey.com
221 * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
225 /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
227 /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
229 var saveAs = saveAs || (function(view) {
231 // IE <10 is explicitly unsupported
232 if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
237 // only get URL when necessary in case Blob.js hasn't overridden it yet
238 , get_URL = function() {
239 return view.URL || view.webkitURL || view;
241 , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
242 , can_use_save_link = "download" in save_link
243 , click = function(node) {
244 var event = new MouseEvent("click");
245 node.dispatchEvent(event);
247 , is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
248 , webkit_req_fs = view.webkitRequestFileSystem
249 , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
250 , throw_outside = function(ex) {
251 (view.setImmediate || view.setTimeout)(function() {
255 , force_saveable_type = "application/octet-stream"
257 // See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
258 // https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
259 // for the reasoning behind the timeout and revocation flow
260 , arbitrary_revoke_timeout = 500 // in ms
261 , revoke = function(file) {
262 var revoker = function() {
263 if (typeof file === "string") { // file is an object URL
264 get_URL().revokeObjectURL(file);
265 } else { // file is a File
272 setTimeout(revoker, arbitrary_revoke_timeout);
275 , dispatch = function(filesaver, event_types, event) {
276 event_types = [].concat(event_types);
277 var i = event_types.length;
279 var listener = filesaver["on" + event_types[i]];
280 if (typeof listener === "function") {
282 listener.call(filesaver, event || filesaver);
289 , auto_bom = function(blob) {
290 // prepend BOM for UTF-8 XML and text/* types (including HTML)
291 if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
292 return new Blob(["\ufeff", blob], {type: blob.type});
296 , FileSaver = function(blob, name, no_auto_bom) {
298 blob = auto_bom(blob);
300 // First try a.download, then web filesystem, then object URLs
304 , blob_changed = false
307 , dispatch_all = function() {
308 dispatch(filesaver, "writestart progress write writeend".split(" "));
310 // on any filesys errors revert to saving with object URLs
311 , fs_error = function() {
312 if (target_view && is_safari && typeof FileReader !== "undefined") {
313 // Safari doesn't allow downloading of blob urls
314 var reader = new FileReader();
315 reader.onloadend = function() {
316 var base64Data = reader.result;
317 target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
318 filesaver.readyState = filesaver.DONE;
321 reader.readAsDataURL(blob);
322 filesaver.readyState = filesaver.INIT;
325 // don't create more object URLs than needed
326 if (blob_changed || !object_url) {
327 object_url = get_URL().createObjectURL(blob);
330 target_view.location.href = object_url;
332 var new_tab = view.open(object_url, "_blank");
333 if (new_tab == undefined && is_safari) {
334 //Apple do not allow window.open, see http://bit.ly/1kZffRI
335 view.location.href = object_url
338 filesaver.readyState = filesaver.DONE;
342 , abortable = function(func) {
344 if (filesaver.readyState !== filesaver.DONE) {
345 return func.apply(this, arguments);
349 , create_if_not_found = {create: true, exclusive: false}
352 filesaver.readyState = filesaver.INIT;
356 if (can_use_save_link) {
357 object_url = get_URL().createObjectURL(blob);
358 setTimeout(function() {
359 save_link.href = object_url;
360 save_link.download = name;
364 filesaver.readyState = filesaver.DONE;
368 // Object and web filesystem URLs have a problem saving in Google Chrome when
369 // viewed in a tab, so I force save with application/octet-stream
370 // http://code.google.com/p/chromium/issues/detail?id=91158
371 // Update: Google errantly closed 91158, I submitted it again:
372 // https://code.google.com/p/chromium/issues/detail?id=389642
373 if (view.chrome && type && type !== force_saveable_type) {
374 slice = blob.slice || blob.webkitSlice;
375 blob = slice.call(blob, 0, blob.size, force_saveable_type);
378 // Since I can't be sure that the guessed media type will trigger a download
379 // in WebKit, I append .download to the filename.
380 // https://bugs.webkit.org/show_bug.cgi?id=65440
381 if (webkit_req_fs && name !== "download") {
384 if (type === force_saveable_type || webkit_req_fs) {
391 fs_min_size += blob.size;
392 req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
393 fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
394 var save = function() {
395 dir.getFile(name, create_if_not_found, abortable(function(file) {
396 file.createWriter(abortable(function(writer) {
397 writer.onwriteend = function(event) {
398 target_view.location.href = file.toURL();
399 filesaver.readyState = filesaver.DONE;
400 dispatch(filesaver, "writeend", event);
403 writer.onerror = function() {
404 var error = writer.error;
405 if (error.code !== error.ABORT_ERR) {
409 "writestart progress write abort".split(" ").forEach(function(event) {
410 writer["on" + event] = filesaver["on" + event];
413 filesaver.abort = function() {
415 filesaver.readyState = filesaver.DONE;
417 filesaver.readyState = filesaver.WRITING;
421 dir.getFile(name, {create: false}, abortable(function(file) {
422 // delete file if it already exists
425 }), abortable(function(ex) {
426 if (ex.code === ex.NOT_FOUND_ERR) {
435 , FS_proto = FileSaver.prototype
436 , saveAs = function(blob, name, no_auto_bom) {
437 return new FileSaver(blob, name, no_auto_bom);
440 // IE 10+ (native saveAs)
441 if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
442 return function(blob, name, no_auto_bom) {
444 blob = auto_bom(blob);
446 return navigator.msSaveOrOpenBlob(blob, name || "download");
450 FS_proto.abort = function() {
451 var filesaver = this;
452 filesaver.readyState = filesaver.DONE;
453 dispatch(filesaver, "abort");
455 FS_proto.readyState = FS_proto.INIT = 0;
456 FS_proto.WRITING = 1;
460 FS_proto.onwritestart =
461 FS_proto.onprogress =
465 FS_proto.onwriteend =
470 typeof self !== "undefined" && self
471 || typeof window !== "undefined" && window
474 // `self` is undefined in Firefox for Android content script context
475 // while `this` is nsIContentFrameMessageManager
476 // with an attribute `content` that corresponds to the window
478 if (typeof module !== "undefined" && module.exports) {
479 module.exports.saveAs = saveAs;
480 } else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
481 define([], function() {
486 },{}],3:[function(require,module,exports){
491 * A AngularJS module that implements the HTML5 W3C saveAs() in browsers that
492 * do not natively support it
494 * (c) 2015 Philipp Alferov
499 angular.module('ngFileSaver', [])
500 .factory('FileSaver', ['Blob', 'SaveAs', 'FileSaverUtils', require('./angular-file-saver.service')])
501 .factory('FileSaverUtils', [require('./utils/utils.service.js')])
502 .factory('Blob', ['$window', require('./dependencies/blob-bundle.service.js')])
503 .factory('SaveAs', [require('./dependencies/file-saver-bundle.service.js')]);
505 },{"./angular-file-saver.service":4,"./dependencies/blob-bundle.service.js":5,"./dependencies/file-saver-bundle.service.js":6,"./utils/utils.service.js":7}],4:[function(require,module,exports){
508 module.exports = function FileSaver(Blob, SaveAs, FileSaverUtils) {
510 function save(blob, filename, disableAutoBOM) {
512 SaveAs(blob, filename, disableAutoBOM);
514 FileSaverUtils.handleErrors(err.message);
522 * Immediately starts saving a file, returns undefined.
526 * @param {Blob} data A Blob instance
527 * @param {Object} filename Custom filename (extension is optional)
528 * @param {Boolean} disableAutoBOM Disable automatically provided Unicode
529 * text encoding hints
531 * @return {Undefined}
534 saveAs: function(data, filename, disableAutoBOM) {
536 if (!FileSaverUtils.isBlobInstance(data)) {
537 FileSaverUtils.handleErrors('Data argument should be a blob instance');
540 if (!FileSaverUtils.isString(filename)) {
541 FileSaverUtils.handleErrors('Filename argument should be a string');
544 return save(data, filename, disableAutoBOM);
549 },{}],5:[function(require,module,exports){
554 module.exports = function Blob($window) {
558 },{"Blob.js":1}],6:[function(require,module,exports){
561 module.exports = function SaveAs() {
562 return require('FileSaver.js').saveAs || function() {};
565 },{"FileSaver.js":2}],7:[function(require,module,exports){
568 module.exports = function FileSaverUtils() {
570 handleErrors: function(msg) {
571 throw new Error(msg);
573 isString: function(obj) {
574 return typeof obj === 'string' || obj instanceof String;
576 isUndefined: function(obj) {
577 return typeof obj === 'undefined';
579 isBlobInstance: function(obj) {
580 return obj instanceof Blob;