Comparing version 1.1.0 to 1.1.1
@@ -60,4 +60,4 @@ // File: block_file.js | ||
* | ||
* @param {string} filename | ||
* @param {number} fd file descriptor from fs.open | ||
* @param {String} filename | ||
* @param {Number} fd file descriptor from fs.open | ||
* @param {Props} [props] | ||
@@ -77,4 +77,2 @@ */ | ||
this.fsm = undefined //this.initialize will `new fsmType(buffer)` this | ||
this.segments = [] //indexed by segment number | ||
@@ -87,9 +85,9 @@ } | ||
BlockFile.Handle = Handle | ||
BlockFile.Props = Props | ||
/** Create a BlockFile | ||
* | ||
* @param {string} filename | ||
* @param {String} filename | ||
* @param {Props} [props] | ||
* @param {function} createcb Callback (err, bf) | ||
* @param {Function} createcb Callback (err, bf) | ||
*/ | ||
@@ -188,5 +186,5 @@ BlockFile.create = function(filename, metaProps_, createcb){ | ||
* | ||
* @param {string} filename | ||
* @param {String} filename | ||
* @param {Props} [props] in case we end up creating the file. | ||
* @param {function} opencb opencb(err, bf) | ||
* @param {Function} opencb opencb(err, bf) | ||
*/ | ||
@@ -316,3 +314,3 @@ BlockFile.open = function(filename, metaProps, opencb){ | ||
* @param {fs.Stats} stat the fstat of the file to initialize | ||
* @param {function} initcb initcb(err, bf) | ||
* @param {Function} initcb initcb(err, bf) | ||
*/ | ||
@@ -372,5 +370,19 @@ BlockFile.prototype.initialize = function(stat, initcb){ | ||
/** | ||
* Write out all segment and block file metadata. | ||
* | ||
* @param {Function} cb cb(err) | ||
*/ | ||
BlockFile.prototype.flush = function(cb){ | ||
var self = this | ||
async.series( [ function(scb){ self.writeSegments(scb) } | ||
, function(scb){ self.writeHeader(scb) } | ||
, function(scb){ fs.fsync(self.fd, scb) } ] | ||
, function(err, res){ if (err) cb(err); else cb(null) }) | ||
} | ||
/** | ||
* Close out BlockFile resources. eg .fd | ||
* | ||
* @param {function} cb cb(err) | ||
* @param {Function} cb cb(err) | ||
*/ | ||
@@ -380,6 +392,11 @@ BlockFile.prototype.close = function(cb){ | ||
async.series( [ function(scb) { self.writeSegments(scb) } | ||
, function(scb) { self.writeHeader(scb) } | ||
, function(scb) { fs.close(self.fd, scb) } ] | ||
, function(err, res){ if (err) cb(err); else cb() } ) | ||
this.flush(function(err){ | ||
if (err) { cb(err); return } | ||
fs.close( self.fd, cb ) | ||
}) | ||
// async.series( [ function(scb) { self.writeSegments(scb) } | ||
// , function(scb) { self.writeHeader(scb) } | ||
// , function(scb) { fs.close(self.fd, scb) } ] | ||
// , function(err, res){ if (err) cb(err); else cb() } ) | ||
} //.close() | ||
@@ -391,3 +408,3 @@ | ||
* | ||
* @param {function} cb cb(err) | ||
* @param {Function} cb cb(err) | ||
*/ | ||
@@ -434,3 +451,3 @@ BlockFile.prototype.writeHeader = function(cb){ | ||
* | ||
* @returns {number} New setment number | ||
* @return {Number} New setment number | ||
*/ | ||
@@ -466,3 +483,3 @@ BlockFile.prototype.addSegment = function(){ | ||
* | ||
* @param {number} segNum | ||
* @param {Number} segNum | ||
* @param {Function} cb Callback (err, segment, segNum) | ||
@@ -538,3 +555,3 @@ */ | ||
* | ||
* @param {number} segNum | ||
* @param {Number} segNum | ||
* @param {Function} cb Callback (err) | ||
@@ -582,3 +599,3 @@ */ | ||
* | ||
* @param {function} [cb] cb(err) | ||
* @param {Function} [cb] cb(err) | ||
*/ | ||
@@ -603,3 +620,3 @@ BlockFile.prototype.writeSegments = function(cb){ | ||
* @param {Handle} hdl | ||
* @returns {undefined} | ||
* @return {undefined} | ||
* @throws {InvalidHandleError} when hdl is not a allocated span of blocks in the givens segment. | ||
@@ -611,4 +628,5 @@ */ | ||
seg.release(hdl) | ||
var ok = seg.release(hdl) | ||
return ok | ||
} //.release() | ||
@@ -620,4 +638,4 @@ | ||
* | ||
* @param {number} numBlks | ||
* @returns {Handle} | ||
* @param {Number} numBlks | ||
* @return {Handle} | ||
*/ | ||
@@ -670,28 +688,18 @@ BlockFile.prototype.reserve = function(numBlks){ | ||
* @param {Function} cb Callback (err, handle) | ||
* @returns {Handle} | ||
* //@return {Handle} | ||
*/ | ||
BlockFile.prototype.store = function(buffer, cb){ | ||
var numBlks, len, segNum, hdl, blkOff | ||
BlockFile.prototype.store = function(buffer, hdl, cb){ | ||
var numBlks | ||
, blkOff | ||
, doneNS = bfStats.get("tt_store ns").start() | ||
numBlks = Math.ceil( buffer.length / this.props.blockSize() ) | ||
if (typeof hdl === 'function') { | ||
cb = hdl | ||
hdl = this.reserve(numBlks) | ||
numBlks = Math.ceil( buffer.length / this.props.blockSize() ) | ||
hdl = this.reserve(numBlks) | ||
} | ||
this._store(buffer, hdl, cb) | ||
//this._store(buffer, hdl, cb) | ||
return hdl | ||
} //.store() | ||
/** | ||
* Store block buffer to an exact location | ||
* | ||
* @param {Buffer} buffer | ||
* @param {Handle} hdl | ||
* @param {function} cb cb(err, hdl) | ||
*/ | ||
BlockFile.prototype._store = function(buffer, hdl, cb){ | ||
var blkOff | ||
, doneNS = bfStats.get("tt_store ns").start() | ||
blkOff = this._calcBlkOff(hdl.segNum, hdl.blkNum) | ||
@@ -709,5 +717,7 @@ fs.write( this.fd | ||
) | ||
} //._store() | ||
//return hdl | ||
} //.store() | ||
//THE END |
@@ -48,9 +48,9 @@ | ||
for ( var curBlockNum = this.props.minBlkNum(); | ||
curBlockNum <= this.props.maxBlkNum(); | ||
curBlockNum += 1 ) | ||
for ( var curBlkNum = this.props.maxBlkNum(); | ||
curBlkNum >= this.props.minBlkNum(); | ||
curBlkNum -= 1 ) | ||
{ | ||
var free = freeBlockMap[curBlockNum] | ||
var free = freeBlockMap[curBlkNum] | ||
, curSpanNum = this.props.minSpanNum() | ||
, begBlkNum = curBlockNum | ||
, endBlkNum = curBlkNum | ||
@@ -60,4 +60,7 @@ if (free) { | ||
while(1) { | ||
if (!free || curSpanNum >= this.props.maxSpanNum() || curBlockNum >= this.props.maxBlkNum()) { | ||
if ( !free || | ||
curSpanNum >= this.props.maxSpanNum() || | ||
curBlkNum <= this.props.minBlkNum() ) { | ||
//capture | ||
var begBlkNum = curBlkNum | ||
this.spans[curSpanNum].push(begBlkNum) | ||
@@ -70,6 +73,6 @@ this.fsiBeg[begBlkNum] = curSpanNum | ||
curBlockNum += 1 | ||
curBlkNum -= 1 | ||
curSpanNum += 1 | ||
free = freeBlockMap[curBlockNum] | ||
free = freeBlockMap[curBlkNum] | ||
} //while(1) | ||
@@ -79,2 +82,5 @@ } //if free | ||
for (var i=0; i<=this.props.maxSpanNum(); i++) | ||
this.spans[i].reverse() | ||
//return this | ||
@@ -90,3 +96,3 @@ } | ||
* @param {NaiveFSM} b | ||
* @returns {boolean} | ||
* @return {Boolean} | ||
*/ | ||
@@ -109,3 +115,3 @@ NaiveFSM.equal = function(a, b){ | ||
* @param {NaiveFSM} fsm | ||
* @returns {boolean} | ||
* @return {Boolean} | ||
*/ | ||
@@ -119,4 +125,4 @@ NaiveFSM.prototype.equal = function(other){ | ||
* | ||
* @param {number} reqSpanNum [reqSpanNum=0] allocate one + spanNum blocks | ||
* @returns {number} begBlkNum where spanNum is implied | ||
* @param {Number} reqSpanNum [reqSpanNum=0] allocate one + spanNum blocks | ||
* @return {Number} begBlkNum where spanNum is implied | ||
*/ | ||
@@ -153,9 +159,21 @@ NaiveFSM.prototype.alloc = function(reqSpanNum){ | ||
/** | ||
* Test if the given blkNum and SpanNum touch any free space. | ||
* | ||
* @param {Number} begBlkNum | ||
* @param {Number} spanNum | ||
* @return {Boolean} | ||
*/ | ||
NaiveFSM.prototype.isFree = function(blkNum, spanNum){ | ||
//this is a cheat for now. otherwise we'd have to scan thru EVERY | ||
//(fsiBeg, spanNum) tuple to see if this (blkNum, spanNum) tuple intersects. | ||
//That is not great :{ | ||
return false | ||
} | ||
//FIXME: remove spanNum argument get value from fsiBeg | ||
/** Release allocated (blkNum, spanNum) tuple | ||
* | ||
* @param {number} begBlkNum first block in a span | ||
* @param {number} spanNum number of additional blocks | ||
* @returns {undefined} | ||
* @param {Number} begBlkNum first block in a span | ||
* @param {Number} spanNum number of additional blocks | ||
* @return {Boolean} | ||
*/ | ||
@@ -166,2 +184,4 @@ NaiveFSM.prototype.free = function(begBlkNum, spanNum){ | ||
if (this.isFree(begBlkNum, spanNum)) return false | ||
var tSpanNum | ||
@@ -216,2 +236,3 @@ , hiBlkNum, hiSpanNum | ||
while (spanNum > this.props.maxSpanNum()) { | ||
// console.warn("****** HERE ******") | ||
// note: spans are designated by (begBlkNum, spanNum) | ||
@@ -221,5 +242,9 @@ //ex span=(0,16) => span'=(0,0) & span2=(1,15) | ||
// span''=(0,0) & span2'=(1,15) | ||
spanNum -= this.props.maxSpanNum() + 1 //16 | ||
begBlkNum2 = begBlkNum+spanNum /*endBlkNum*/ + 1 | ||
// spanNum -= this.props.maxSpanNum() + 1 | ||
// begBlkNum2 = begBlkNum+spanNum /*endBlkNum*/ + 1 | ||
// spanNum2 = this.props.maxSpanNum() | ||
spanNum2 = this.props.maxSpanNum() | ||
begBlkNum2 = begBlkNum+spanNum /*endBlkNum*/ - spanNum2 - 1 | ||
spanNum -= spanNum2 + 1 | ||
@@ -230,2 +255,4 @@ this._insert(begBlkNum2, spanNum2) | ||
this._insert(begBlkNum, spanNum) | ||
return true | ||
} //.free() | ||
@@ -232,0 +259,0 @@ |
@@ -22,5 +22,5 @@ | ||
* @constructor | ||
* @param {number} segNum Segment number the block resides in | ||
* @param {number} blkNum Block number of first block in the given segment | ||
* @param {number} spanNum Number of additional "blocks" handle identifies beyody one (eg 1+spanNum) | ||
* @param {Number} segNum Segment number the block resides in | ||
* @param {Number} blkNum Block number of first block in the given segment | ||
* @param {Number} spanNum Number of additional "blocks" handle identifies beyody one (eg 1+spanNum) | ||
*/ | ||
@@ -43,3 +43,3 @@ exports = module.exports = Handle | ||
* inclusive. | ||
* @param {number} segNum | ||
* @param {Number} segNum | ||
* @throws {Error} | ||
@@ -59,3 +59,3 @@ */ | ||
* | ||
* @param {number} blkNum | ||
* @param {Number} blkNum | ||
* @throws {Error} | ||
@@ -76,3 +76,3 @@ */ | ||
* inclusive. | ||
* @param {number} spanNum | ||
* @param {Number} spanNum | ||
* @throws {Error} | ||
@@ -92,4 +92,4 @@ */ | ||
/* Tests if given segment number is within [MIN_SEGNUM..MAX_SEGNUM] inclusive. | ||
* @param {number} segNum | ||
* @returns {boolean} | ||
* @param {Number} segNum | ||
* @return {Boolean} | ||
*/ | ||
@@ -102,4 +102,4 @@ Handle.isValidSegNum = function(segNum, props){ | ||
/* Tests if given block number is within [MIN_BLOCKNUM..MAX_BLOCKNUM] inclusive. | ||
* @param {number} blkNum | ||
* @returns {boolean} | ||
* @param {Number} blkNum | ||
* @return {Boolean} | ||
*/ | ||
@@ -112,4 +112,4 @@ Handle.isValidBlockNum = function(blkNum, props){ | ||
/* Tests if given span number is within [MIN_SPANNUM..MAX_SPANNUM] inclusive. | ||
* @param {number} spanNum | ||
* @returns {boolean} | ||
* @param {Number} spanNum | ||
* @return {Boolean} | ||
*/ | ||
@@ -127,7 +127,8 @@ Handle.isValidSpanNum = function(spanNum, props){ | ||
* @param {Handle} b | ||
* @return {boolean} | ||
* @return {Boolean} | ||
*/ | ||
Handle.equals = function(a, b) { | ||
return a instanceof Handle && b instanceof Handle && | ||
a.props.equals(b.props) && | ||
// assert(a instanceof Handle, "Handle.equals: a !instanceof Handle") | ||
// assert(b instanceof Handle, "Handle.equals: b !instanceof Handle") | ||
return a.props.equals(b.props) && | ||
a.segNum === b.segNum && | ||
@@ -143,13 +144,13 @@ a.blkNum === b.blkNum && | ||
* @param {Handle} other | ||
* @return {boolean} | ||
* @return {Boolean} | ||
*/ | ||
Handle.prototype.equals = function(other) { | ||
// assert(other instanceof Handle, "Handle#equals: other !instanceof Handle") | ||
return Handle.equals(this, other) | ||
} | ||
/** | ||
* Encode a handle into a 32 or 64 (based on props) value. | ||
* | ||
* @returns {number} | ||
* @return {Number} | ||
*/ | ||
@@ -170,3 +171,3 @@ Handle.prototype.encode = function(){ | ||
* | ||
* @param {number} hdlv 32bit handle value | ||
* @param {Number} hdlv 32bit handle value | ||
* @param {Props} [props] | ||
@@ -194,3 +195,3 @@ * @return {Handle} | ||
* | ||
* @returns {string} | ||
* @return {String} | ||
*/ | ||
@@ -197,0 +198,0 @@ Handle.prototype.toString = function(){ |
@@ -207,6 +207,13 @@ | ||
u.keys(defaultMetaProps) | ||
.forEach(function(k){ t = (t && self[k] === other[k]) }) | ||
// u.keys(defaultMetaProps) | ||
// .forEach(function(k){ t = (t && self[k] === other[k]) }) | ||
// | ||
// return t | ||
return t | ||
return this.blockSzBits === other.blockSzBits && | ||
this.fsmSzBits === other.fsmSzBits && | ||
this.checkSumBits === other.checkSumBits && | ||
this.checkSumOffset === other.checkSumOffset && | ||
this.numHandleBits === other.numHandleBits && | ||
this.spanNumBits === other.spanNumBits | ||
} | ||
@@ -213,0 +220,0 @@ |
@@ -17,5 +17,5 @@ | ||
* @constructor | ||
* @param {number} segNum | ||
* @param {Number} segNum | ||
* @param {Buffer} buffer | ||
* @param {function} fsmType | ||
* @param {Function} fsmType | ||
* | ||
@@ -58,4 +58,4 @@ */ | ||
* | ||
* @param {number} blkNum MIN_BLOCKNUM <= blkNum <= MAX_BLOCKNUM | ||
* @returns {boolean} free == true | ||
* @param {Number} blkNum MIN_BLOCKNUM <= blkNum <= MAX_BLOCKNUM | ||
* @return {Boolean} free == true | ||
*/ | ||
@@ -75,5 +75,5 @@ Segment.prototype.get = function(blkNum){ | ||
* | ||
* @param {number} blkNum | ||
* @param {boolean} v | ||
* @returns {Segment} | ||
* @param {Number} blkNum | ||
* @param {Boolean} v | ||
* @return {Segment} | ||
*/ | ||
@@ -95,3 +95,3 @@ Segment.prototype.set = function(blkNum, v){ | ||
* @param {Number} numBlks reserve a number of blocks within this Segment | ||
* @returns {Handle|undefined} | ||
* @return {Handle} | ||
*/ | ||
@@ -125,5 +125,9 @@ Segment.prototype.reserve = function(numBlks){ | ||
this.fsm.free(hdl.blkNum, hdl.spanNum) | ||
var ok = this.fsm.free(hdl.blkNum, hdl.spanNum) | ||
if (ok) { | ||
this.dirty = true | ||
return true | ||
} | ||
this.dirty = true | ||
return false | ||
} | ||
@@ -130,0 +134,0 @@ |
@@ -7,18 +7,3 @@ | ||
, crc32 = require('crc').buffer.crc32 | ||
, fprintf = require('printf') | ||
var printf = exports.printf = function(){ | ||
var args = Array.prototype.slice.call(arguments) | ||
args.unshift(process.stdout) | ||
fprintf.apply(this, args) | ||
} | ||
var eprintf = exports.eprintf = function(){ | ||
var args = Array.prototype.slice.call(arguments) | ||
args.unshift(process.stderr) | ||
fprintf.apply(this, args) | ||
} | ||
exports.err = function(){ | ||
@@ -78,7 +63,7 @@ var args = Array.prototype.slice.call(arguments) | ||
* Stolen form https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String | ||
* @param {string} str | ||
* @param {number} n | ||
* @returns {string} | ||
* @param {String} str | ||
* @param {Number} n | ||
* @return {String} | ||
*/ | ||
var repeatst = exports.repeatStr = function(str, n) { | ||
var repeatStr = exports.repeatStr = function(str, n) { | ||
var sd = "" | ||
@@ -97,4 +82,4 @@ , s2 = n > 0 ? str : "" | ||
* @param {Buffer} buffer | ||
* @param {number} bit | ||
* @returns {number} 0 or 1 | ||
* @param {Number} bit | ||
* @return {Number} 0 or 1 | ||
*/ | ||
@@ -118,5 +103,5 @@ var readBit = exports.readBit = function readBit(buffer, bit) { | ||
* @param {Buffer} buffer | ||
* @param {number} bit index of bit from beginning of buffer | ||
* @param {boolean} value true/false value of bit to be set true=1 false=0 | ||
* @returns {undefined} | ||
* @param {Number} bit index of bit from beginning of buffer | ||
* @param {Boolean} value true/false value of bit to be set true=1 false=0 | ||
* @return {undefined} | ||
*/ | ||
@@ -146,4 +131,4 @@ var writeBit = exports.writeBit = function writeBit(buffer, bit, value) { | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {number} the CRC16 | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Number} the CRC16 | ||
*/ | ||
@@ -168,4 +153,4 @@ exports.calculateCRC16 = calculateCRC16 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {number} the CRC16 | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Number} the CRC16 | ||
*/ | ||
@@ -182,4 +167,4 @@ exports.readCRC16 = readCRC16 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {Buffer} | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Buffer} | ||
*/ | ||
@@ -201,4 +186,4 @@ exports.signCRC16 = signCRC16 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {boolean} true for matching CRC, false for no-match | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Boolean} true for matching CRC, false for no-match | ||
*/ | ||
@@ -216,4 +201,4 @@ exports.validateCRC16 = validateCRC16 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {number} the CRC32 | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Number} the CRC32 | ||
*/ | ||
@@ -243,4 +228,4 @@ exports.calculateCRC32 = calculateCRC32 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {number} the CRC32 | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Number} the CRC32 | ||
*/ | ||
@@ -259,4 +244,4 @@ exports.readCRC32 = readCRC32 | ||
* @param {Buffer} buffer | ||
* @param {number} [offset=0] byte offset into buffer | ||
* @returns {Buffer} | ||
* @param {Number} [offset=0] byte offset into buffer | ||
* @return {Buffer} | ||
*/ | ||
@@ -287,3 +272,3 @@ exports.signCRC32 = signCRC32 | ||
* @param {Buffer} buffer | ||
* @returns {boolean} true for matching CRC, false for no-match | ||
* @return {Boolean} true for matching CRC, false for no-match | ||
*/ | ||
@@ -290,0 +275,0 @@ exports.validateCRC32 = validateCRC32 |
{ | ||
"name" : "block-file" | ||
, "version" : "1.1.0" | ||
, "version" : "1.1.1" | ||
, "description" : "A library to read/write blocks from a file" | ||
@@ -23,5 +23,3 @@ , "keywords" : ["block", "buffer", "storage"] | ||
, "lib/utils.js" | ||
, "test/lorem-ipsum.1k.txt" | ||
, "test/lorem-ipsum.4k.txt" | ||
, "test/lorem-ipsum.64k.txt" | ||
, "test/lorem-ipsum.254.txt" | ||
, "test/00-basic.js" | ||
@@ -28,0 +26,0 @@ , "test/01-Handle.js" |
@@ -16,10 +16,12 @@ /* global describe it */ | ||
, NUM_BLOCKNUM = props.numBlkNums() | ||
, utils = require('../lib/utils') | ||
, strOps = require('../lib/str_ops') | ||
var filename ='test.bf' | ||
, err, fnStat | ||
, lorem4k_fn = 'test/lorem-ipsum.4k.txt' | ||
, lorem256_fn = 'test/lorem-ipsum.254.txt' | ||
, lorem256Str | ||
, lorem4kStr | ||
, lorem4kSiz | ||
, lorem4kBuf | ||
, lorem64k_fn = 'test/lorem-ipsum.64k.txt' | ||
, lorem64kStr | ||
@@ -41,3 +43,7 @@ , lorem64kSiz | ||
lorem4kStr = fs.readFileSync(lorem4k_fn, 'utf8') | ||
lorem256Str = fs.readFileSync(lorem256_fn, 'utf8') | ||
assert.equal(lorem256Str.length, 254) //we need 2 spare bytes for string size | ||
lorem4kStr = strOps.mult(lorem256Str, 4*4) | ||
assert.equal(lorem4kStr.length, 254*4*4) | ||
lorem4kSiz = Buffer.byteLength( lorem4kStr, 'utf8' ) | ||
@@ -48,3 +54,4 @@ lorem4kBuf = new Buffer( 2 + lorem4kSiz ) | ||
lorem64kStr = fs.readFileSync(lorem64k_fn, 'utf8') | ||
lorem64kStr = strOps.mult(lorem256Str, 4*64) | ||
assert.equal(lorem64kStr.length, 254*4*64) | ||
lorem64kSiz = Buffer.byteLength( lorem64kStr, 'utf8' ) | ||
@@ -106,3 +113,3 @@ lorem64kBuf = new Buffer( 2 + lorem64kSiz ) | ||
var i = lastIdx | ||
var i = lastIdx // i == 0 | ||
@@ -152,3 +159,3 @@ blks[i] = {/*str: lorem, siz: num, hdl: Handle*/} | ||
it("Read the previous 4k buffer from file", function(done){ | ||
var i = lastIdx | ||
var i = lastIdx //still i == 0 | ||
@@ -197,4 +204,4 @@ bf.load(blks[i].hdl, function(err, buf, hdl){ | ||
lastIdx = nextIdx | ||
nextIdx = lastIdx + (NUM_BLOCKNUM-1) | ||
lastIdx = nextIdx //== 1 | ||
nextIdx = lastIdx + NUM_BLOCKNUM //== NUM_BLOCKNUM+1 | ||
@@ -262,8 +269,8 @@ var i = lastIdx | ||
var i = nextIdx - NUM_BLOCKNUM | ||
, end = i + NUM_BLOCKNUM | ||
var i = nextIdx - NUM_BLOCKNUM - 1 // i == 0 | ||
, last = i + NUM_BLOCKNUM //NUM_BLOCKNUM | ||
async.whilst( | ||
/*test*/ | ||
function() { return i < end } | ||
function() { return i < last+1 } | ||
/*body*/ | ||
@@ -318,6 +325,6 @@ , function(loop){ | ||
lastIdx = nextIdx | ||
lastIdx = nextIdx //NUM_BLOCKNUM+1 | ||
nextIdx = lastIdx + 1 | ||
var i = lastIdx | ||
var i = lastIdx //NUM_BLOCKNUM+1 | ||
@@ -371,4 +378,4 @@ blks[i] = {/*str: lorem, siz: num, hdl: Handle*/} | ||
lastIdx = nextIdx | ||
nextIdx = lastIdx + (NUM_BLOCKNUM-1) | ||
lastIdx = nextIdx //NUM_BLOCKNUM+1 | ||
nextIdx = lastIdx + NUM_BLOCKNUM //NUM_BLOCKNUM + 1 + NUM_BLOCKNUM | ||
@@ -641,3 +648,3 @@ var i = lastIdx | ||
describe("Write the stats aut to "+outputFN, function(){ | ||
describe("Write the stats out to "+outputFN, function(){ | ||
it("should dump BlockFile.STATS", function(done){ | ||
@@ -644,0 +651,0 @@ fs.writeFile(outputFN, BlockFile.STATS.toString({values:"both"})+"\n" |
@@ -17,20 +17,14 @@ /* global describe it */ | ||
, floor = Math.floor | ||
, strOps = require('../lib/str_ops') | ||
var filename ='test-alt.bf' | ||
, fnStat | ||
, lorem1k_fn = 'test/lorem-ipsum.1k.txt' | ||
, lorem256_fn = 'test/lorem-ipsum.254.txt' | ||
, lorem256Str | ||
, lorem1kStr | ||
, lorem1kSiz | ||
, lorem1kBuf | ||
, lorem4k_fn = 'test/lorem-ipsum.4k.txt' | ||
, lorem4kStr | ||
, lorem4kSiz | ||
, lorem4kBuf | ||
, lorem64k_fn = 'test/lorem-ipsum.64k.txt' | ||
, lorem64kStr | ||
, lorem64kSiz | ||
, lorem64kBuf | ||
, lorem256kStr | ||
, lorem256kSiz | ||
, lorem256kBuf | ||
, outputFN = "stats-alt.txt" | ||
@@ -48,3 +42,6 @@ | ||
lorem1kStr = fs.readFileSync(lorem1k_fn, 'utf8') | ||
lorem256Str = fs.readFileSync(lorem256_fn, 'utf8') | ||
assert.equal(lorem256Str.length, 254) //we need 2 spare bytes for string size | ||
lorem1kStr = strOps.repeat(lorem256Str, 4) | ||
lorem1kSiz = Buffer.byteLength( lorem1kStr, 'utf8' ) | ||
@@ -57,11 +54,3 @@ lorem1kBuf = new Buffer( 4 + lorem1kSiz ) | ||
lorem4kStr = fs.readFileSync(lorem4k_fn, 'utf8') | ||
lorem4kSiz = Buffer.byteLength( lorem4kStr, 'utf8' ) | ||
lorem4kBuf = new Buffer( 4 + lorem4kSiz ) | ||
lorem4kBuf.writeUInt32BE( lorem4kSiz, 0 ) | ||
lorem4kBuf.write( lorem4kStr, 4, lorem4kSiz, 'utf8' ) | ||
assert.ok(lorem4kBuf.length <= 4*1024) //lorem4kStr.length < 4*1024-4 | ||
assert.ok(lorem4kBuf.length > 3*1024) | ||
lorem64kStr = fs.readFileSync(lorem64k_fn, 'utf8') | ||
lorem64kStr = strOps.mult(lorem1kStr, 64) | ||
lorem64kSiz = Buffer.byteLength( lorem64kStr, 'utf8' ) | ||
@@ -74,11 +63,2 @@ lorem64kBuf = new Buffer( 4 + lorem64kSiz ) | ||
lorem256kStr = utils.repeatStr(lorem64kStr+"\n", 4) | ||
lorem256kSiz = Buffer.byteLength( lorem256kStr, 'utf8' ) | ||
lorem256kBuf = new Buffer( 4 + lorem256kSiz ) | ||
lorem256kBuf.writeUInt32BE( lorem256kSiz, 0 ) | ||
lorem256kBuf.write( lorem256kStr, 4, lorem256kSiz, 'utf8' ) | ||
assert.ok(lorem256kBuf.length <= 256*1024) //lorem256kStr.length < 256*1024-4 | ||
assert.ok(lorem256kBuf.length > 255*1024) //lorem256kStr.length < 256*1024-4 | ||
describe("BlockFile w/alternative metaProps", function(){ | ||
@@ -107,3 +87,2 @@ var metaProps = { numHandleBits: 64 | ||
//utils.err("spanNumBits = %j", props.spanNumBits) | ||
//utils.err("lorem256kSiz = %j", lorem256kSiz) | ||
@@ -110,0 +89,0 @@ done() |
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
2666
97677
15