'use strict'; const debug = require("debug")("iso9660:parse:path-table"); const roundEven = require("../../round-even"); const parsePathTableRecord = require("./path-table-record"); module.exports = function parsePathTable(buffer, sectorSize) { function roundToNextSector(position) { return Math.ceil(position / sectorSize) * sectorSize; } let records = []; let pos = 0; while (pos < buffer.length) { let recordIdentifierLength = buffer.readUInt8(pos); let recordLength = roundEven(recordIdentifierLength + 8); if (recordIdentifierLength === 0) { /* Reached the end of records for this section, throw away the remainder. */ debug("Ran out of records, skipping to next sector..."); pos = roundToNextSector(pos); } else { let parsedRecord = parsePathTableRecord(buffer.slice(pos, pos + recordLength), "L"); debug(`Found: ${parsedRecord.identifier.filename}`); records.push(parsedRecord); pos += recordLength; } } return records; };