ENCODING!! and lots of organization

This commit is contained in:
2023-09-13 14:50:27 -05:00
parent 2ab90d0146
commit fa0160fc54
37 changed files with 651 additions and 222 deletions
+7
View File
@@ -0,0 +1,7 @@
const SystemNameChunk = require('./info-system-name-chunk');
const TrackerListChunk = require('./info-tracker-list-chunk');
module.exports = {
SystemNameChunk,
TrackerListChunk,
};
+3
View File
@@ -0,0 +1,3 @@
const Parser = require('binary-parser').Parser;
module.exports = new Parser().string('system_name', { greedy: true });
+39
View File
@@ -0,0 +1,39 @@
const Parser = require('binary-parser').Parser;
const infoTrackerNameParser = new Parser()
.uint16le('id')
.uint16le('data_len', {
formatter: (item) => {
const binary = item.toString(2).padStart(16, '0');
return Number.parseInt(binary.substring(1), 2);
},
})
.seek(-2)
.uint16le('has_subchunks', {
formatter: (item) => {
const binary = item.toString(2).padStart(16, '0');
return binary.charAt(0) === '1';
},
})
.string('tracker_name', { length: 'data_len' });
const infoTrackerParser = new Parser()
.uint16le('id')
.uint16le('data_len', {
formatter: (item) => {
const binary = item.toString(2).padStart(16, '0');
return Number.parseInt(binary.substring(1), 2);
},
})
.seek(-2)
.uint16le('has_subchunks', {
formatter: (item) => {
const binary = item.toString(2).padStart(16, '0');
return binary.charAt(0) === '1';
},
})
.nest('tracker_name', {
type: infoTrackerNameParser,
});
module.exports = new Parser().array('trackers', { type: infoTrackerParser, readUntil: 'eof' });