-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
leveldown-hyper.js
118 lines (94 loc) · 3.42 KB
/
leveldown-hyper.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
111
112
113
114
115
116
117
118
const util = require('util')
const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
const binding = require('bindings')('leveldownhyper.node').leveldown
const ChainedBatch = require('./chained-batch')
const Iterator = require('./iterator')
function LevelDOWNHyper (location) {
if (!(this instanceof LevelDOWNHyper)) {
return new LevelDOWNHyper(location)
}
AbstractLevelDOWN.call(this, location)
this.binding = binding(location)
}
util.inherits(LevelDOWNHyper, AbstractLevelDOWN)
LevelDOWNHyper.prototype._open = function (options, callback) {
this.binding.open(options, callback)
}
LevelDOWNHyper.prototype._close = function (callback) {
this.binding.close(callback)
}
LevelDOWNHyper.prototype._put = function (key, value, options, callback) {
this.binding.put(key, value, options, callback)
}
LevelDOWNHyper.prototype._get = function (key, options, callback) {
this.binding.get(key, options, callback)
}
LevelDOWNHyper.prototype._del = function (key, options, callback) {
this.binding.del(key, options, callback)
}
LevelDOWNHyper.prototype._chainedBatch = function () {
return new ChainedBatch(this)
}
LevelDOWNHyper.prototype._batch = function (operations, options, callback) {
return this.binding.batch(operations, options, callback)
}
LevelDOWNHyper.prototype.approximateSize = function (start, end, callback) {
if (start == null ||
end == null ||
typeof start === 'function' ||
typeof end === 'function') {
throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments')
}
if (typeof callback !== 'function') {
throw new Error('approximateSize() requires a callback argument')
}
start = this._serializeKey(start)
end = this._serializeKey(end)
this.binding.approximateSize(start, end, callback)
}
LevelDOWNHyper.prototype.getProperty = function (property) {
if (typeof property !== 'string') {
throw new Error('getProperty() requires a valid `property` argument')
}
return this.binding.getProperty(property)
}
LevelDOWNHyper.prototype.liveBackup = function (name, callback) {
if (arguments.length < 2) {
throw new Error('liveBackup() requires `name` and `callback` arguments')
}
if (typeof name !== 'string') {
throw new Error('liveBackup() requires a name string argument')
}
if (typeof callback !== 'function') {
throw new Error('liveBackup() requires a callback function argument')
}
this.binding.liveBackup(name, callback)
}
LevelDOWNHyper.prototype._iterator = function (options) {
return new Iterator(this, options)
}
LevelDOWNHyper.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)
}
LevelDOWNHyper.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 = LevelDOWNHyper