align structure more with underlying chunk layout

This commit is contained in:
2025-01-06 21:49:08 -06:00
parent acac519e9a
commit 6580f66e91
35 changed files with 594 additions and 372 deletions
+23 -14
View File
@@ -1,24 +1,33 @@
import { Decoders } from '..';
import { Constants } from '../../constants';
import { InfoTrackerListChunk } from '../../models/info/info-tracker-list-chunk';
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk';
import { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk';
function decodeInfoTrackerListChunk(infoTrackerListChunk: InfoTrackerListChunk) {
infoTrackerListChunk.trackers = {};
if (infoTrackerListChunk.has_subchunks && infoTrackerListChunk.chunk_data) {
export default (buffer: Uint8Array): InfoTrackerListChunk => {
const chunk = Decoders.Chunk(buffer);
const trackers: InfoTrackerChunk[] = [];
if (chunk.header.hasSubchunks && chunk.chunkData) {
let offset = 0;
if (infoTrackerListChunk.data_len) {
while (offset < infoTrackerListChunk.data_len) {
const trackerChunk = Decoders.InfoTrackerChunk(infoTrackerListChunk.chunk_data.slice(offset));
if (chunk.header.dataLen) {
while (offset < chunk.header.dataLen) {
const trackerChunk = Decoders.InfoTrackerChunk(chunk.chunkData.subarray(offset));
offset += Constants.CHUNK_HEADER_SIZE;
if (trackerChunk.data_len) {
offset += trackerChunk.data_len;
if (trackerChunk.chunk.header.dataLen) {
offset += trackerChunk.chunk.header.dataLen;
}
if (trackerChunk.id !== undefined) {
infoTrackerListChunk.trackers[trackerChunk.id] = trackerChunk;
if (trackerChunk.chunk.header.id !== undefined) {
trackers.push(trackerChunk);
}
}
}
}
}
export default (buffer: Uint8Array): InfoTrackerListChunk =>
Decoders.Chunk(buffer, decodeInfoTrackerListChunk) as InfoTrackerListChunk;
const data: InfoTrackerListChunkData = {
trackers,
};
return {
chunk,
data,
};
};