chaindb: minor.

This commit is contained in:
Christopher Jeffrey 2016-01-20 21:14:50 -08:00
parent f62cf7dc6e
commit 423b52b0b7

View File

@ -827,10 +827,10 @@ ChainDB.prototype.del = function del(height) {
// If we deleted several blocks at the end, go back
// to the last non-null block and truncate the file
// beyond that point.
if (height * BLOCK_SIZE + BLOCK_SIZE === this.size()) {
if ((height + 1) * BLOCK_SIZE === this.size()) {
while (this.isNull(height))
height--;
fs.ftruncateSync(this.fd, height * BLOCK_SIZE + BLOCK_SIZE);
fs.ftruncateSync(this.fd, (height + 1) * BLOCK_SIZE);
}
return true;
@ -845,8 +845,8 @@ ChainDB.prototype.isNull = function isNull(height) {
ChainDB.prototype._read = function _read(size, offset) {
var data = this.getBuffer(size);
var bytes = 0;
var index = 0;
var bytes;
if (offset < 0 || offset == null)
return;
@ -866,15 +866,12 @@ ChainDB.prototype._read = function _read(size, offset) {
ChainDB.prototype._write = function _write(data, offset, callback) {
var self = this;
var size, bytes, index;
var size = data.length;
var index = 0;
if (offset < 0 || offset == null)
return false;
size = data.length;
bytes = 0;
index = 0;
(function callee() {
fs.write(self.fd, data, index, size, offset, function(err, bytes) {
if (err)
@ -893,15 +890,13 @@ ChainDB.prototype._write = function _write(data, offset, callback) {
};
ChainDB.prototype._writeSync = function _writeSync(data, offset) {
var size, bytes, index;
var size = data.length;
var index = 0;
var bytes;
if (offset < 0 || offset == null)
return false;
size = data.length;
bytes = 0;
index = 0;
while (bytes = fs.writeSync(this.fd, data, index, size, offset)) {
index += bytes;
size -= bytes;