ogg-helpers.js
837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPages = void 0;
var _byteHelpers = require("./byte-helpers");
var SYNC_WORD = (0, _byteHelpers.toUint8)([0x4f, 0x67, 0x67, 0x53]);
var getPages = function getPages(bytes, start, end) {
if (end === void 0) {
end = Infinity;
}
bytes = (0, _byteHelpers.toUint8)(bytes);
var pages = [];
var i = 0;
while (i < bytes.length && pages.length < end) {
// we are unsynced,
// find the next syncword
if (!(0, _byteHelpers.bytesMatch)(bytes, SYNC_WORD, {
offset: i
})) {
i++;
continue;
}
var segmentLength = bytes[i + 27];
pages.push(bytes.subarray(i, i + 28 + segmentLength));
i += pages[pages.length - 1].length;
}
return pages.slice(start, end);
};
exports.getPages = getPages;