Comparing version 4.4.8 to 4.4.9
'use strict' | ||
// Tar can encode large and negative numbers using a leading byte of | ||
// 0xff for negative, and 0x80 for positive. The trailing byte in the | ||
// section will always be 0x20, or in some implementations 0x00. | ||
// this module encodes and decodes these things. | ||
// 0xff for negative, and 0x80 for positive. | ||
const encode = exports.encode = (num, buf) => { | ||
buf[buf.length - 1] = 0x20 | ||
if (num < 0) | ||
if (!Number.isSafeInteger(num)) | ||
// The number is so large that javascript cannot represent it with integer | ||
// precision. | ||
throw TypeError('cannot encode number outside of javascript safe integer range') | ||
else if (num < 0) | ||
encodeNegative(num, buf) | ||
@@ -18,9 +19,6 @@ else | ||
buf[0] = 0x80 | ||
for (var i = buf.length - 2; i > 0; i--) { | ||
if (num === 0) | ||
buf[i] = 0 | ||
else { | ||
buf[i] = num % 0x100 | ||
num = Math.floor(num / 0x100) | ||
} | ||
for (var i = buf.length; i > 1; i--) { | ||
buf[i-1] = num & 0xff | ||
num = Math.floor(num / 0x100) | ||
} | ||
@@ -33,17 +31,12 @@ } | ||
num = num * -1 | ||
for (var i = buf.length - 2; i > 0; i--) { | ||
var byte | ||
if (num === 0) | ||
byte = 0 | ||
else { | ||
byte = num % 0x100 | ||
num = Math.floor(num / 0x100) | ||
} | ||
for (var i = buf.length; i > 1; i--) { | ||
var byte = num & 0xff | ||
num = Math.floor(num / 0x100) | ||
if (flipped) | ||
buf[i] = onesComp(byte) | ||
buf[i-1] = onesComp(byte) | ||
else if (byte === 0) | ||
buf[i] = 0 | ||
buf[i-1] = 0 | ||
else { | ||
flipped = true | ||
buf[i] = twosComp(byte) | ||
buf[i-1] = twosComp(byte) | ||
} | ||
@@ -56,4 +49,16 @@ } | ||
var pre = buf[0] | ||
return pre === 0x80 ? pos(buf.slice(1, buf.length - 1)) | ||
: twos(buf.slice(1, buf.length - 1)) | ||
var value; | ||
if (pre === 0x80) | ||
value = pos(buf.slice(1, buf.length)) | ||
else if (pre === 0xff) | ||
value = twos(buf) | ||
else | ||
throw TypeError('invalid base256 encoding') | ||
if (!Number.isSafeInteger(value)) | ||
// The number is so large that javascript cannot represent it with integer | ||
// precision. | ||
throw TypeError('parsed number outside of javascript safe integer range') | ||
return value | ||
} | ||
@@ -77,5 +82,5 @@ | ||
if (f !== 0) | ||
sum += f * Math.pow(256, len - i - 1) | ||
sum -= f * Math.pow(256, len - i - 1) | ||
} | ||
return sum * -1 | ||
return sum | ||
} | ||
@@ -82,0 +87,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "tar for node", | ||
"version": "4.4.8", | ||
"version": "4.4.9", | ||
"repository": { | ||
@@ -12,3 +12,3 @@ "type": "git", | ||
"scripts": { | ||
"test": "tap test/*.js --100 -J --coverage-report=text -c", | ||
"test": "tap", | ||
"preversion": "npm test", | ||
@@ -23,7 +23,7 @@ "postversion": "npm publish", | ||
"fs-minipass": "^1.2.5", | ||
"minipass": "^2.3.4", | ||
"minizlib": "^1.1.1", | ||
"minipass": "^2.3.5", | ||
"minizlib": "^1.2.1", | ||
"mkdirp": "^0.5.0", | ||
"safe-buffer": "^5.1.2", | ||
"yallist": "^3.0.2" | ||
"yallist": "^3.0.3" | ||
}, | ||
@@ -35,4 +35,4 @@ "devDependencies": { | ||
"mutate-fs": "^2.1.1", | ||
"rimraf": "^2.6.2", | ||
"tap": "^12.0.1", | ||
"rimraf": "^2.6.3", | ||
"tap": "^14.2.0", | ||
"tar-fs": "^1.16.3", | ||
@@ -48,3 +48,7 @@ "tar-stream": "^1.6.2" | ||
"lib/" | ||
] | ||
], | ||
"tap": { | ||
"coverage-map": "map.js", | ||
"check-coverage": true | ||
} | ||
} |
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
133548
2978
Updatedminipass@^2.3.5
Updatedminizlib@^1.2.1
Updatedyallist@^3.0.3