/*
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 { 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 let IGExcelSerializationProvider_SyncZipFile = /*@__PURE__*/ (() => {
    class IGExcelSerializationProvider_SyncZipFile extends Base {
        constructor() {
            super();
            this.a = null;
            this.a = new List$1(IZipEntry_$type, 0);
        }
        get entries() {
            return this.a;
        }
        createFile(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);
        }
        _createFile$i(a, b, c) {
            let d = typeCast(MemoryStream.$, c);
            if (d == null) {
                let e = DocCoreUtils.c(c);
                d = new MemoryStream(2, e);
            }
            return new IGExcelSerializationProvider_SyncZipEntry(stringReplace(IOPath.combine1(b, a), '\\', '/'), false, d);
        }
        load(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);
        }
        _load$i(a) {
            let b = Encoding.uTF8;
            let c = new BinaryReader(1, a);
            let d = c.readInt32();
            for (let e = 0; e < d; e++) {
                let f = c.readInt32();
                let g = c.readBytes(f);
                let h = b.getString(g);
                let i = c.readInt32();
                let j = c.readBytes(i);
                let k = new MemoryStream(2, (Pako.inflate(j)));
                let l = new IGExcelSerializationProvider_SyncZipEntry(h, false, k);
                this.entries.add(l);
            }
            return WorkItem.h(IZipFile_$type, this);
        }
        save(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);
        }
        _save$i(a) {
            let b = Encoding.uTF8;
            let c = new BinaryWriter(1, a);
            c.q(this.entries.count);
            for (let d = 0; d < this.a.count; d++) {
                let e = this.a._inner[d];
                if (!e.isDirectory) {
                    let f = e.name;
                    let g = e.b;
                    if (f.charAt(0) == '/') {
                        f = f.substr(1);
                    }
                    let h = b.getBytes1(f);
                    c.q(h.length);
                    c.h(h);
                    let i = g.toArray();
                    let j = (Pako.deflate(i));
                    c.q(j.length);
                    c.h(j);
                }
            }
            c.g();
            return null;
        }
    }
    IGExcelSerializationProvider_SyncZipFile.$t = /*@__PURE__*/ markType(IGExcelSerializationProvider_SyncZipFile, 'IGExcelSerializationProvider_SyncZipFile', Base.$, [IZipFile_$type]);
    return IGExcelSerializationProvider_SyncZipFile;
})();
//# sourceMappingURL=IGExcelSerializationProvider_SyncZipFile.js.map
