Comparing version 0.4.2 to 0.4.3
@@ -278,2 +278,30 @@ /* Copyright (c) 2012 Rod Vagg <@rvagg> */ | ||
, approximateSize: function(start, end, callback) { | ||
var err | ||
if (!this.isOpen() && !this.isClosed()) { | ||
return this.once('ready', function () { | ||
this.approximateSize(start, end, callback) | ||
}) | ||
} | ||
if (this.isClosed()) { | ||
err = new errors.WriteError('Database is not open') | ||
if (callback) | ||
return callback(err) | ||
throw err | ||
} | ||
this._db.approximateSize(start, end, function(err, size) { | ||
if (err) { | ||
err = new errors.OpenError(err) | ||
if (callback) | ||
return callback(err) | ||
this.emit('error', err) | ||
} else { | ||
callback && callback(null, size) | ||
} | ||
}); | ||
} | ||
, readStream: function (options) { | ||
@@ -280,0 +308,0 @@ options = extend(extend({}, this._options), typeof options == 'object' ? options : {}) |
@@ -16,3 +16,3 @@ { | ||
] | ||
, "version": "0.4.2" | ||
, "version": "0.4.3" | ||
, "main": "lib/levelup.js" | ||
@@ -19,0 +19,0 @@ , "dependencies": { |
@@ -73,2 +73,3 @@ LevelUP | ||
* <a href="#batch"><code>db.<b>batch()</b></code></a> | ||
* <a href="#approximateSize"><code>db.<b>approximateSize()</b></code></a> | ||
* <a href="#isOpen"><code>db.<b>isOpen()</b></code></a> | ||
@@ -201,2 +202,14 @@ * <a href="#isClosed"><code>db.<b>isClosed()</b></code></a> | ||
-------------------------------------------------------- | ||
<a name='approximateSize'></a> | ||
### db.approximateSize(start, end, callback) | ||
<code>approximateSize()</code> can used to get the approximate number of bytes of file system space used by the range `[start..end)`. The result may not include recently written data. | ||
```js | ||
db.approximateSize('a', 'c', function (err, size) { | ||
if (err) return console.error('Ooops!', err) | ||
console.log('Approximate size of range is %d', size) | ||
}) | ||
``` | ||
-------------------------------------------------------- | ||
<a name="isOpen"></a> | ||
@@ -384,2 +397,3 @@ ### db.isOpen() | ||
* Lars-Magnus Skog - [GitHub/ralphtheninja](https://github.com/ralphtheninja) - [Twitter/@ralphtheninja](https://twitter.com/ralphtheninja) | ||
* David Björklund - [GitHub/kesla](https://github.com/kesla) - [Twitter/david_bjorklund](https://twitter.com/david_bjorklund) | ||
@@ -386,0 +400,0 @@ <a name="licence"></a> |
@@ -412,2 +412,65 @@ /* Copyright (c) 2012 Rod Vagg <@rvagg> */ | ||
, 'approximateSize()': { | ||
'approximateSize() works on empty database': function (done) { | ||
this.openTestDatabase(function (db) { | ||
db.approximateSize('a', 'z', function(err, size) { | ||
refute(err) // sanity | ||
assert.equals(size, 0) | ||
done() | ||
}) | ||
}) | ||
} | ||
, 'approximateSize() work on none-empty database': function(done) { | ||
var location = common.nextLocation() | ||
var db | ||
async.series( | ||
[ | ||
function (callback) { | ||
this.openTestDatabase( | ||
location | ||
, function (_db) { | ||
db = _db | ||
callback() | ||
} | ||
) | ||
}.bind(this) | ||
, function (callback) { | ||
var batch = []; | ||
for(var i = 0; i < 10; ++i) { | ||
batch.push({ | ||
type: 'put', key: String(i), value: 'afoovalue' | ||
}); | ||
} | ||
db.batch( | ||
batch | ||
, { sync: true } | ||
, callback | ||
) | ||
} | ||
, function (callback) { | ||
// close db to make sure stuff gets written to disc | ||
db.close(callback) | ||
} | ||
, function (callback) { | ||
levelup(location, function (err, _db) { | ||
refute(err) | ||
db = _db | ||
callback() | ||
} | ||
) | ||
} | ||
, function (callback) { | ||
db.approximateSize('', '99', function(err, size) { | ||
refute(err) // sanity | ||
refute.equals(size, 0) | ||
done() | ||
}) | ||
} | ||
] | ||
, done | ||
) | ||
} | ||
} | ||
, 'null and undefined': { | ||
@@ -414,0 +477,0 @@ 'setUp': function (done) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
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
2992787
235
2941
406
1