/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Base, Stream, typeCast, markType } from "igniteui-webcomponents-core";
import { IZipFile_$type } from "igniteui-webcomponents-excel";
import { List$1 } from "igniteui-webcomponents-core";
import { IZipEntry_$type } from "igniteui-webcomponents-excel";
import { MemoryStream } from "igniteui-webcomponents-core";
import { DocCoreUtils } from "igniteui-webcomponents-excel";
import { IOPath } from "igniteui-webcomponents-core";
import { IGExcelSerializationProvider_SyncZipEntry } from "./IGExcelSerializationProvider_SyncZipEntry";
import { Encoding } from "igniteui-webcomponents-core";
import { BinaryReader } from "igniteui-webcomponents-core";
import { WorkItem } from "igniteui-webcomponents-excel";
import { BinaryWriter } from "igniteui-webcomponents-core";
import { b64toUint8Array } from "igniteui-webcomponents-core";
import { stringReplace } from "igniteui-webcomponents-core";
import * as Pako from "pako";
/**
 * @hidden
 */
export var IGExcelSerializationProvider_SyncZipFile = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(IGExcelSerializationProvider_SyncZipFile, _super);
    function IGExcelSerializationProvider_SyncZipFile() {
        var _this = _super.call(this) || this;
        _this.a = null;
        _this.a = new List$1(IZipEntry_$type, 0);
        return _this;
    }
    Object.defineProperty(IGExcelSerializationProvider_SyncZipFile.prototype, "entries", {
        get: function () {
            return this.a;
        },
        enumerable: false,
        configurable: true
    });
    IGExcelSerializationProvider_SyncZipFile.prototype.createFile = function (fileName, directoryName, stream) {
        arguments[2] = (typeof arguments[2] === 'string' ? b64toUint8Array(arguments[2]) : arguments[2]);
        arguments[2] = (typeCast(Stream.$, arguments[2]) ? arguments[2] : new MemoryStream(2, arguments[2]));
        return this._createFile$i.apply(this, arguments);
    };
    IGExcelSerializationProvider_SyncZipFile.prototype._createFile$i = function (a, b, c) {
        var d = typeCast(MemoryStream.$, c);
        if (d == null) {
            var e = DocCoreUtils.c(c);
            d = new MemoryStream(2, e);
        }
        return new IGExcelSerializationProvider_SyncZipEntry(stringReplace(IOPath.combine1(b, a), '\\', '/'), false, d);
    };
    IGExcelSerializationProvider_SyncZipFile.prototype.load = function (stream) {
        arguments[0] = (typeof arguments[0] === 'string' ? b64toUint8Array(arguments[0]) : arguments[0]);
        arguments[0] = (typeCast(Stream.$, arguments[0]) ? arguments[0] : new MemoryStream(2, arguments[0]));
        return this._load$i.apply(this, arguments);
    };
    IGExcelSerializationProvider_SyncZipFile.prototype._load$i = function (a) {
        var b = Encoding.uTF8;
        var c = new BinaryReader(1, a);
        var d = c.readInt32();
        for (var e = 0; e < d; e++) {
            var f = c.readInt32();
            var g = c.readBytes(f);
            var h = b.getString(g);
            var i = c.readInt32();
            var j = c.readBytes(i);
            var k = new MemoryStream(2, (Pako.inflate(j)));
            var l = new IGExcelSerializationProvider_SyncZipEntry(h, false, k);
            this.entries.add(l);
        }
        return WorkItem.h(IZipFile_$type, this);
    };
    IGExcelSerializationProvider_SyncZipFile.prototype.save = function (stream) {
        arguments[0] = (typeof arguments[0] === 'string' ? b64toUint8Array(arguments[0]) : arguments[0]);
        arguments[0] = (typeCast(Stream.$, arguments[0]) ? arguments[0] : new MemoryStream(2, arguments[0]));
        return this._save$i.apply(this, arguments);
    };
    IGExcelSerializationProvider_SyncZipFile.prototype._save$i = function (a) {
        var b = Encoding.uTF8;
        var c = new BinaryWriter(1, a);
        c.q(this.entries.count);
        for (var d = 0; d < this.a.count; d++) {
            var e = this.a._inner[d];
            if (!e.isDirectory) {
                var f = e.name;
                var g = e.b;
                if (f.charAt(0) == '/') {
                    f = f.substr(1);
                }
                var h = b.getBytes1(f);
                c.q(h.length);
                c.h(h);
                var i = g.toArray();
                var j = (Pako.deflate(i));
                c.q(j.length);
                c.h(j);
            }
        }
        c.g();
        return null;
    };
    IGExcelSerializationProvider_SyncZipFile.$t = markType(IGExcelSerializationProvider_SyncZipFile, 'IGExcelSerializationProvider_SyncZipFile', Base.$, [IZipFile_$type]);
    return IGExcelSerializationProvider_SyncZipFile;
}(Base));
