mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-09-10 16:49:46 +00:00
align structure more with underlying chunk layout
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user