const { unzip, table } = require("./import-estx.cjs"); function inspectAccom(bytes) { const files = unzip(bytes), data = files.get("accommaintable.dat"); if (!data) throw Error("기성 원본 표 AccomMainTable.Dat가 없습니다."); const signature = Buffer.from("068abe8e592364cb403d71d2e3bc64d001", "hex"); if (data.length < 512 || !data.subarray(8, 25).equals(signature)) throw Error("기성 원본 표의 DBISAM 서명이 올바르지 않습니다."); const warnings = new Set(), rows = table(data, files.get("accommaintable.blb"), warnings), fields = Array.from({ length: data.readUInt16LE(47) }, (_, index) => { const at = 512 + index * 768; return data.subarray(at + 3, at + 3 + data[at + 2]).toString("ascii"); }); if (!["Code", "TotalGN"].every((name) => fields.includes(name))) throw Error("기성 원본 표의 코드 또는 누계 수량 필드가 없습니다."); if (new Set(fields).size !== fields.length) throw Error("기성 원본 표에 중복 필드가 있습니다."); const hasBlob = fields.some((_, index) => data[512 + index * 768 + 164] === 3); if (hasBlob && !files.has("accommaintable.blb")) warnings.add("기성 표의 BLOB 파일이 없어 별도 바이너리 값은 확인할 수 없습니다."); return { fields, rows: rows.map((row) => Object.fromEntries( fields.map((field) => [ field, row[field] && typeof row[field] === "object" ? "[바이너리]" : row[field], ]), ), ), warnings: [...warnings], }; } module.exports = { inspectAccom };