quick tweaks to clamp.
This commit is contained in:
parent
4d31ce9d77
commit
a606c781a7
2 changed files with 18 additions and 18 deletions
18
headers.js
18
headers.js
|
@ -2,15 +2,15 @@ var ZEROS = '0000000000000000000';
|
|||
var ZERO_OFFSET = '0'.charCodeAt(0);
|
||||
var USTAR = 'ustar00';
|
||||
|
||||
function clamp(index, len, defaultValue) {
|
||||
if (typeof index !== 'number') return defaultValue;
|
||||
index = ~~index; // Coerce to integer.
|
||||
if (index >= len) return len;
|
||||
if (index >= 0) return index;
|
||||
index += len;
|
||||
if (index >= 0) return index;
|
||||
return 0;
|
||||
}
|
||||
var clamp = function(index, len, defaultValue) {
|
||||
if (typeof index !== 'number') return defaultValue;
|
||||
index = ~~index; // Coerce to integer.
|
||||
if (index >= len) return len;
|
||||
if (index >= 0) return index;
|
||||
index += len;
|
||||
if (index >= 0) return index;
|
||||
return 0;
|
||||
};
|
||||
|
||||
var toType = function(flag) {
|
||||
switch (flag) {
|
||||
|
|
|
@ -4,15 +4,15 @@ var fixtures = require('./fixtures');
|
|||
var concat = require('concat-stream');
|
||||
var fs = require('fs');
|
||||
|
||||
function clamp(index, len, defaultValue) {
|
||||
if (typeof index !== 'number') return defaultValue;
|
||||
index = ~~index; // Coerce to integer.
|
||||
if (index >= len) return len;
|
||||
if (index >= 0) return index;
|
||||
index += len;
|
||||
if (index >= 0) return index;
|
||||
return 0;
|
||||
}
|
||||
var clamp = function(index, len, defaultValue) {
|
||||
if (typeof index !== 'number') return defaultValue;
|
||||
index = ~~index; // Coerce to integer.
|
||||
if (index >= len) return len;
|
||||
if (index >= 0) return index;
|
||||
index += len;
|
||||
if (index >= 0) return index;
|
||||
return 0;
|
||||
};
|
||||
|
||||
test('one-file', function(t) {
|
||||
t.plan(3);
|
||||
|
|
Loading…
Reference in a new issue