mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-18 13:44:20 +00:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
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' });
|