You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB
JavaScript

'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;
};