"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZZPlayasEmbedParser = void 0;
const fs_1 = __importDefault(require("fs"));
class ZZPlayasEmbedParser {
    h = Buffer.from("!PlayAsManifest0");
    constructor() { }
    parse(file) {
        let buf;
        if (Buffer.isBuffer(file)) {
            buf = file;
        }
        else {
            buf = fs_1.default.readFileSync(file);
        }
        let head = buf.indexOf(this.h) + this.h.byteLength;
        let map = {};
        let entries = buf.readUInt16BE(head);
        head += 2;
        let ascii_convert = Buffer.alloc(1);
        for (let i = 0; i < entries; i++) {
            try {
                let str = "";
                let cur = buf.readUInt8(head);
                // Start seeking for the end of the ascii.
                while (cur !== 0) {
                    ascii_convert[0] = cur;
                    str += ascii_convert.toString();
                    head++;
                    cur = buf.readUInt8(head);
                }
                head++;
                let offset = buf.readUInt32BE(head);
                head += 4;
                map[str] = offset;
            }
            catch (err) {
                break;
            }
        }
        return map;
    }
}
exports.ZZPlayasEmbedParser = ZZPlayasEmbedParser;
//# sourceMappingURL=ZZPlayasEmbedParser.js.map