UNPKG

@ohayojp.com/components

Version:

Common business components of ohayojp.

7 lines 3.26 kB
/** * @license ohayojp(cipchk@qq.com) v1.0.0 * (c) 2020 cipchk https://ohayojp.com/ * License: MIT */ !function (e, n) { "object" == typeof exports && "undefined" != typeof module ? n(exports, require("@angular/common/http"), require("@angular/core"), require("@ohayojp.com/util"), require("file-saver"), require("@angular/common")) : "function" == typeof define && define.amd ? define("@ohayojp.com/components/zip", ["exports", "@angular/common/http", "@angular/core", "@ohayojp.com/util", "file-saver", "@angular/common"], n) : n(((e = "undefined" != typeof globalThis ? globalThis : e || self).ohayo = e.ohayo || {}, e.ohayo.components = e.ohayo.components || {}, e.ohayo.components.zip = {}), e.ng.common.http, e.ng.core, e.ohayo.util, e.saveAs, e.ng.common) }(this, (function (e, n, t, o, r, i) { "use strict"; var c = function () { function e(e, n, t, o) { this.http = e, this.lazy = n, this.ngZone = o, this.cog = t.merge("zip", { url: "//cdn.bootcss.com/jszip/3.3.0/jszip.min.js", utils: [] }) } return e.prototype.init = function () { return this.lazy.load([this.cog.url].concat(this.cog.utils)) }, e.prototype.check = function (e) { if (!e) throw new Error("get instance via `ZipService.create()`") }, e.prototype.read = function (e, n) { var t = this; return new Promise((function (o, r) { var i = function (e) { t.ngZone.run((function () { return o(e) })) }; t.init().then((function () { t.ngZone.runOutsideAngular((function () { if ("string" != typeof e) { var o = new FileReader; o.onload = function (e) { JSZip.loadAsync(e.target.result, n).then((function (e) { return i(e) })) }, o.readAsBinaryString(e) } else t.http.request("GET", e, { responseType: "arraybuffer" }).subscribe((function (e) { JSZip.loadAsync(e, n).then((function (e) { return i(e) })) }), (function (e) { r(e) })) })) })) })) }, e.prototype.create = function () { var e = this; return new Promise((function (n) { e.init().then((function () { var e = new JSZip; n(e) })) })) }, e.prototype.pushUrl = function (e, n, t) { var o = this; return this.check(e), new Promise((function (r, i) { o.http.request("GET", t, { responseType: "arraybuffer" }).subscribe((function (t) { e.file(n, t), r() }), (function (e) { i({ url: t, error: e }) })) })) }, e.prototype.save = function (e, n) { this.check(e); var t = Object.assign({}, n); return new Promise((function (n, o) { e.generateAsync(Object.assign({ type: "blob" }, t.options), t.update).then((function (e) { t.callback && t.callback(e), r.saveAs(e, t.filename || "download.zip"), n() }), (function (e) { o(e) })) })) }, e }(); c.decorators = [{ type: t.Injectable, args: [{ providedIn: "root" }] }], c.ctorParameters = function () { return [{ type: n.HttpClient }, { type: o.LazyService }, { type: o.OhayoConfigService }, { type: t.NgZone }] }, c.ɵprov = t.ɵɵdefineInjectable({ factory: function () { return new c(t.ɵɵinject(n.HttpClient), t.ɵɵinject(o.LazyService), t.ɵɵinject(o.OhayoConfigService), t.ɵɵinject(t.NgZone)) }, token: c, providedIn: "root" }); var u = function () { }; u.decorators = [{ type: t.NgModule, args: [{ imports: [i.CommonModule, o.OhayoUtilModule] }] }], e.ZipModule = u, e.ZipService = c, Object.defineProperty(e, "__esModule", { value: !0 }) })); //# sourceMappingURL=zip.umd.min.js.map