organize models and new modules

This commit is contained in:
2023-09-16 14:27:05 -05:00
parent 489d32ae78
commit 64a3709cac
29 changed files with 240 additions and 120 deletions
+4 -9
View File
@@ -1,19 +1,14 @@
import { Decoders } from '..';
import { Constants } from '../../constants';
import chunk, { Chunk } from '../chunk';
import infoTrackerChunk, { InfoTrackerChunk } from './info-tracker-chunk';
import { InfoTrackerListChunk } from '../../models/info/info-tracker-list-chunk';
export interface InfoTrackerListChunk extends Chunk {
trackers: {
[key: number]: InfoTrackerChunk;
};
}
function decodeInfoTrackerListChunk(infoTrackerListChunk: InfoTrackerListChunk) {
infoTrackerListChunk.trackers = {};
if (infoTrackerListChunk.has_subchunks && infoTrackerListChunk.chunk_data) {
let offset = 0;
if (infoTrackerListChunk.data_len) {
while (offset < infoTrackerListChunk.data_len) {
const trackerChunk = infoTrackerChunk(infoTrackerListChunk.chunk_data.subarray(offset));
const trackerChunk = Decoders.InfoTrackerChunk(infoTrackerListChunk.chunk_data.subarray(offset));
offset += Constants.CHUNK_HEADER_SIZE;
if (trackerChunk.data_len) {
offset += trackerChunk.data_len;
@@ -26,4 +21,4 @@ function decodeInfoTrackerListChunk(infoTrackerListChunk: InfoTrackerListChunk)
}
}
export default (buffer: Buffer): InfoTrackerListChunk =>
chunk(buffer, decodeInfoTrackerListChunk) as InfoTrackerListChunk;
Decoders.Chunk(buffer, decodeInfoTrackerListChunk) as InfoTrackerListChunk;