This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
leveldown.js
110 lines (70 loc) · 2.74 KB
/
leveldown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const util = require('util')
, AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN;
var binding;
if (process.versions.embedded && process.versions.embedded.leveldown) {
binding = jxcore.embeddedModule.require('leveldown').leveldown;
} else {
var path = require('path');
var build_path = path.join(__dirname, 'build/Release/leveldown.node');
binding = require(build_path).leveldown;
}
var ChainedBatch = require('./chained-batch')
, Iterator = require('./iterator')
function LevelDOWN (location) {
if (!(this instanceof LevelDOWN))
return new LevelDOWN(location)
AbstractLevelDOWN.call(this, location)
this.binding = binding(location)
}
util.inherits(LevelDOWN, AbstractLevelDOWN)
LevelDOWN.prototype._open = function (options, callback) {
this.binding.open(options, callback)
}
LevelDOWN.prototype._close = function (callback) {
this.binding.close(callback)
}
LevelDOWN.prototype._put = function (key, value, options, callback) {
this.binding.put(key, value, options, callback)
}
LevelDOWN.prototype._get = function (key, options, callback) {
this.binding.get(key, options, callback)
}
LevelDOWN.prototype._del = function (key, options, callback) {
this.binding.del(key, options, callback)
}
LevelDOWN.prototype._chainedBatch = function () {
return new ChainedBatch(this)
}
LevelDOWN.prototype._batch = function (operations, options, callback) {
return this.binding.batch(operations, options, callback)
}
LevelDOWN.prototype._approximateSize = function (start, end, callback) {
this.binding.approximateSize(start, end, callback)
}
LevelDOWN.prototype.getProperty = function (property) {
if (typeof property != 'string')
throw new Error('getProperty() requires a valid `property` argument')
return this.binding.getProperty(property)
}
LevelDOWN.prototype._iterator = function (options) {
return new Iterator(this, options)
}
LevelDOWN.destroy = function (location, callback) {
if (arguments.length < 2)
throw new Error('destroy() requires `location` and `callback` arguments')
if (typeof location != 'string')
throw new Error('destroy() requires a location string argument')
if (typeof callback != 'function')
throw new Error('destroy() requires a callback function argument')
binding.destroy(location, callback)
}
LevelDOWN.repair = function (location, callback) {
if (arguments.length < 2)
throw new Error('repair() requires `location` and `callback` arguments')
if (typeof location != 'string')
throw new Error('repair() requires a location string argument')
if (typeof callback != 'function')
throw new Error('repair() requires a callback function argument')
binding.repair(location, callback)
}
module.exports = LevelDOWN