1- var duplexify = require ( 'duplexify' )
2- var abstract = require ( 'abstract-leveldown' )
3- var util = require ( 'util' )
4- var eos = require ( 'end-of-stream' )
5- var ids = require ( 'numeric-id-map' )
6- var lpstream = require ( 'length-prefixed-stream' )
7- var reachdown = require ( 'reachdown' )
8- var messages = require ( './messages' )
9- var matchdown = require ( './matchdown' )
10-
11- var ENCODERS = [
1+ const duplexify = require ( 'duplexify' )
2+ const abstract = require ( 'abstract-leveldown' )
3+ const util = require ( 'util' )
4+ const eos = require ( 'end-of-stream' )
5+ const ids = require ( 'numeric-id-map' )
6+ const lpstream = require ( 'length-prefixed-stream' )
7+ const reachdown = require ( 'reachdown' )
8+ const messages = require ( './messages' )
9+ const matchdown = require ( './matchdown' )
10+
11+ const ENCODERS = [
1212 messages . Get ,
1313 messages . Put ,
1414 messages . Delete ,
1515 messages . Batch ,
1616 messages . Iterator
1717]
1818
19- var DECODERS = [
19+ const DECODERS = [
2020 messages . Callback ,
2121 messages . IteratorData
2222]
@@ -47,18 +47,19 @@ Multilevel.prototype.createRpcStream = function (opts, proxy) {
4747 if ( ! opts ) opts = { }
4848 this . _ref = opts . ref || null
4949
50- var self = this
51- var encode = this . _encode
52- var decode = lpstream . decode ( )
50+ const self = this
51+ const encode = this . _encode
52+ const decode = lpstream . decode ( )
5353
5454 decode . on ( 'data' , function ( data ) {
5555 if ( ! data . length ) return
56- var tag = data [ 0 ]
56+ const tag = data [ 0 ]
5757 if ( tag >= DECODERS . length ) return
5858
59- var dec = DECODERS [ tag ]
59+ const dec = DECODERS [ tag ]
60+ let res
6061 try {
61- var res = dec . decode ( data , 1 )
62+ res = dec . decode ( data , 1 )
6263 } catch ( err ) {
6364 return
6465 }
@@ -93,29 +94,29 @@ Multilevel.prototype.createRpcStream = function (opts, proxy) {
9394 return
9495 }
9596
96- for ( var i = 0 ; i < self . _requests . length ; i ++ ) {
97- var req = self . _requests . get ( i )
97+ for ( let i = 0 ; i < self . _requests . length ; i ++ ) {
98+ const req = self . _requests . get ( i )
9899 if ( ! req ) continue
99100 self . _write ( req )
100101 }
101102
102- for ( var j = 0 ; j < self . _iterators . length ; j ++ ) {
103- var ite = self . _iterators . get ( j )
103+ for ( let j = 0 ; j < self . _iterators . length ; j ++ ) {
104+ const ite = self . _iterators . get ( j )
104105 if ( ! ite ) continue
105106 ite . options = ite . iterator . _options
106107 self . _write ( ite )
107108 }
108109 }
109110
110111 function oniteratordata ( res ) {
111- var req = self . _iterators . get ( res . id )
112+ const req = self . _iterators . get ( res . id )
112113 if ( ! req ) return
113114 req . pending . push ( res )
114115 if ( req . callback ) req . iterator . next ( req . callback )
115116 }
116117
117118 function oncallback ( res ) {
118- var req = self . _requests . remove ( res . id )
119+ const req = self . _requests . remove ( res . id )
119120 if ( req ) req . callback ( decodeError ( res . error ) , decodeValue ( res . value , req . valueAsBuffer ) )
120121 }
121122}
@@ -135,13 +136,13 @@ Multilevel.prototype._flushMaybe = function () {
135136}
136137
137138Multilevel . prototype . _clearRequests = function ( closing ) {
138- for ( var i = 0 ; i < this . _requests . length ; i ++ ) {
139- var req = this . _requests . remove ( i )
139+ for ( let i = 0 ; i < this . _requests . length ; i ++ ) {
140+ const req = this . _requests . remove ( i )
140141 if ( req ) req . callback ( new Error ( 'Connection to leader lost' ) )
141142 }
142143
143- for ( var j = 0 ; j < this . _iterators . length ; j ++ ) {
144- var ite = this . _iterators . remove ( j )
144+ for ( let j = 0 ; j < this . _iterators . length ; j ++ ) {
145+ const ite = this . _iterators . remove ( j )
145146 if ( ite ) {
146147 if ( ite . callback && ! closing ) ite . callback ( new Error ( 'Connection to leader lost' ) )
147148 ite . iterator . end ( )
@@ -160,7 +161,7 @@ Multilevel.prototype._serializeValue = function (value) {
160161Multilevel . prototype . _get = function ( key , opts , cb ) {
161162 if ( this . _db ) return this . _db . _get ( key , opts , cb )
162163
163- var req = {
164+ const req = {
164165 tag : 0 ,
165166 id : 0 ,
166167 key : key ,
@@ -175,7 +176,7 @@ Multilevel.prototype._get = function (key, opts, cb) {
175176Multilevel . prototype . _put = function ( key , value , opts , cb ) {
176177 if ( this . _db ) return this . _db . _put ( key , value , opts , cb )
177178
178- var req = {
179+ const req = {
179180 tag : 1 ,
180181 id : 0 ,
181182 key : key ,
@@ -190,7 +191,7 @@ Multilevel.prototype._put = function (key, value, opts, cb) {
190191Multilevel . prototype . _del = function ( key , opts , cb ) {
191192 if ( this . _db ) return this . _db . _del ( key , opts , cb )
192193
193- var req = {
194+ const req = {
194195 tag : 2 ,
195196 id : 0 ,
196197 key : key ,
@@ -204,7 +205,7 @@ Multilevel.prototype._del = function (key, opts, cb) {
204205Multilevel . prototype . _batch = function ( batch , opts , cb ) {
205206 if ( this . _db ) return this . _db . _batch ( batch , opts , cb )
206207
207- var req = {
208+ const req = {
208209 tag : 3 ,
209210 id : 0 ,
210211 ops : batch ,
@@ -217,8 +218,8 @@ Multilevel.prototype._batch = function (batch, opts, cb) {
217218
218219Multilevel . prototype . _write = function ( req ) {
219220 if ( this . _requests . length + this . _iterators . length === 1 ) ref ( this . _ref )
220- var enc = ENCODERS [ req . tag ]
221- var buf = Buffer . allocUnsafe ( enc . encodingLength ( req ) + 1 )
221+ const enc = ENCODERS [ req . tag ]
222+ const buf = Buffer . allocUnsafe ( enc . encodingLength ( req ) + 1 )
222223 buf [ 0 ] = req . tag
223224 enc . encode ( req , buf , 1 )
224225 this . _encode . write ( buf )
@@ -252,7 +253,7 @@ function Iterator (parent, opts) {
252253 this . _valueAsBuffer = opts . valueAsBuffer
253254 this . _options = opts
254255
255- var req = {
256+ const req = {
256257 tag : 4 ,
257258 id : 0 ,
258259 batch : 32 ,
@@ -281,16 +282,16 @@ Iterator.prototype.next = function (cb) {
281282 this . _parent . _write ( this . _req )
282283 }
283284
284- var next = this . _req . pending . shift ( )
285+ const next = this . _req . pending . shift ( )
285286 if ( next . error ) return cb ( decodeError ( next . error ) )
286287
287288 if ( ! next . key && ! next . value ) return cb ( )
288289
289290 this . _options . gt = next . key
290291 if ( this . _options . limit > 0 ) this . _options . limit --
291292
292- var key = decodeValue ( next . key , this . _keyAsBuffer )
293- var val = decodeValue ( next . value , this . _valueAsBuffer )
293+ const key = decodeValue ( next . key , this . _keyAsBuffer )
294+ const val = decodeValue ( next . value , this . _valueAsBuffer )
294295 return cb ( undefined , key , val )
295296 }
296297
0 commit comments