binary-bitfield
Advanced tools
Comparing version 2.0.10 to 2.56.8
@@ -59,3 +59,3 @@ "use strict"; | ||
this.bitfield = this.setPieces(this.pieces); | ||
this.downloaded = this.totalBitfield = (downloaded) | ||
this.downloaded = (downloaded) | ||
? this.d2binary(downloaded) | ||
@@ -95,3 +95,3 @@ : this.setZeros(this.pieces); | ||
} | ||
let addZero = 8 - (result.length % 8); | ||
let addZero = (result.length % 8) ? (8 - (result.length % 8)) : 0; | ||
while (addZero) { | ||
@@ -153,18 +153,18 @@ result += '0'; | ||
} | ||
for (let i = 0; i < bits.length; i++) { | ||
if (self.downloaded[i] === '0' && bits[i] === '1') | ||
result += '1'; | ||
else | ||
result += '0'; | ||
if (bits[i] === '1') { | ||
let num = Number(self.totalBitfield[i]); | ||
num++; | ||
add2total += num; | ||
process.nextTick(() => { | ||
for (let i = 0; i < bits.length; i++) { | ||
if (self.downloaded[i] === '0' && bits[i] === '1') | ||
result += '1'; | ||
else | ||
result += '0'; | ||
if (bits[i] === '1') { | ||
let num = Number(self.downloaded[i]); | ||
num++; | ||
add2total += num; | ||
} | ||
else | ||
add2total += self.downloaded[i]; | ||
} | ||
else | ||
add2total += self.totalBitfield[i]; | ||
} | ||
self.totalBitfield = add2total; | ||
process.nextTick(() => { | ||
cb(self.binary2hex(result), self.totalBitfield); | ||
self.downloaded = add2total; | ||
cb(self.binary2hex(result), self.downloaded); | ||
}); | ||
@@ -171,0 +171,0 @@ } |
@@ -51,3 +51,2 @@ import { Buffer } from 'buffer'; | ||
bitfield: string | ||
totalBitfield: string | ||
downloaded: string | ||
@@ -71,3 +70,3 @@ percent: number | ||
this.bitfield = this.setPieces(this.pieces); | ||
this.downloaded = this.totalBitfield = (downloaded) | ||
this.downloaded = (downloaded) | ||
? this.d2binary(downloaded) | ||
@@ -110,3 +109,3 @@ : this.setZeros(this.pieces); | ||
} | ||
let addZero = 8 - (result.length % 8); | ||
let addZero = (result.length % 8) ? (8 - (result.length % 8)) : 0; | ||
while (addZero) { | ||
@@ -175,18 +174,18 @@ result += '0'; | ||
} | ||
for (let i = 0; i < bits.length; i++) { | ||
if (self.downloaded[i] === '0' && bits[i] === '1') | ||
result += '1'; | ||
else | ||
result += '0'; | ||
if (bits[i] === '1') { | ||
let num = Number(self.totalBitfield[i]); | ||
num++; | ||
add2total += num; | ||
process.nextTick(() => { | ||
for (let i = 0; i < bits.length; i++) { | ||
if (self.downloaded[i] === '0' && bits[i] === '1') | ||
result += '1'; | ||
else | ||
result += '0'; | ||
if (bits[i] === '1') { | ||
let num = Number(self.downloaded[i]); | ||
num++; | ||
add2total += num; | ||
} | ||
else | ||
add2total += self.downloaded[i]; | ||
} | ||
else | ||
add2total += self.totalBitfield[i]; | ||
} | ||
self.totalBitfield = add2total; | ||
process.nextTick(() => { | ||
cb(self.binary2hex(result), self.totalBitfield); | ||
self.downloaded = add2total; | ||
cb(self.binary2hex(result), self.downloaded); | ||
}); | ||
@@ -193,0 +192,0 @@ } |
{ | ||
"name": "binary-bitfield", | ||
"version": "2.0.10", | ||
"version": "2.56.8", | ||
"description": "Binary bitfield system to easily keep track of torrent pieces", | ||
@@ -5,0 +5,0 @@ "main": "binary-bitfield.js", |
11
test.js
"use strict"; | ||
const binary_bitfield_1 = require("./binary-bitfield"); | ||
let bitfield = new binary_bitfield_1.default('c0', '40'); | ||
let y = Buffer.from('40', 'hex'); | ||
let bitfield = new binary_bitfield_1.default('c0'); | ||
let y = Buffer.from('80', 'hex'); | ||
bitfield.findNewPieces(y, (result, total) => { | ||
console.log('b2: ', bitfield); | ||
console.log('r2: ', result); | ||
console.log('t2: ', total); | ||
}); | ||
console.log(bitfield.set(0)); | ||
console.log(bitfield); | ||
console.log(bitfield.get(1)); | ||
console.log('b1: ', bitfield); |
13
test.ts
@@ -26,11 +26,14 @@ import binaryBitfield from './binary-bitfield'; | ||
let bitfield = new binaryBitfield('c0', '40'); | ||
let bitfield = new binaryBitfield('c0'); | ||
let y = Buffer.from('40', 'hex'); | ||
let y = Buffer.from('80', 'hex'); | ||
bitfield.findNewPieces(y, (result, total) => { | ||
console.log('b2: ' ,bitfield); | ||
console.log('r2: ' ,result); | ||
console.log('t2: ' ,total); | ||
}); | ||
//console.log(bitfield.set(0)); | ||
console.log(bitfield.set(0)); | ||
console.log(bitfield); | ||
console.log(bitfield.get(1)); | ||
console.log('b1: ' ,bitfield); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16444
414