level-codec
Advanced tools
+4
-3
@@ -23,5 +23,6 @@ var encodings = require('./lib/encodings'); | ||
| Codec.prototype._valueEncoding = function(opts, batchOpts){ | ||
| return this._encoding(batchOpts && batchOpts.valueEncoding | ||
| || opts && opts.valueEncoding | ||
| || this.opts.valueEncoding); | ||
| return this._encoding( | ||
| batchOpts && (batchOpts.valueEncoding || batchOpts.encoding) | ||
| || opts && (opts.valueEncoding || opts.encoding) | ||
| || (this.opts.valueEncoding || this.opts.encoding)); | ||
| }; | ||
@@ -28,0 +29,0 @@ |
+1
-1
| { | ||
| "name": "level-codec", | ||
| "repository": "Level/codec", | ||
| "version": "6.0.0", | ||
| "version": "6.1.0", | ||
| "description": "Levelup's encoding logic", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
+27
-0
@@ -30,1 +30,28 @@ var test = require('tape'); | ||
| test('batch - legacy', function(t){ | ||
| var codec = new Codec({}); | ||
| var ops = [ | ||
| { type: 'put', key: 'string', value: 'string', encoding: 'utf8' }, | ||
| { type: 'put', key: 'json', value: {} } | ||
| ]; | ||
| var opsSerialized = JSON.stringify(ops); | ||
| var encoded = codec.encodeBatch(ops, { encoding: 'json' }); | ||
| t.equal(opsSerialized, JSON.stringify(ops), 'ops not changed'); | ||
| t.deepEqual(encoded, [ | ||
| { type: 'put', key: 'string', value: 'string' }, | ||
| { type: 'put', key: 'json', value: '{}' } | ||
| ]); | ||
| encoded = codec.encodeBatch(ops); | ||
| t.deepEqual(encoded, [ | ||
| { type: 'put', key: 'string', value: 'string' }, | ||
| { type: 'put', key: 'json', value: {} } | ||
| ]); | ||
| t.end(); | ||
| }); | ||
+34
-0
@@ -37,1 +37,35 @@ var test = require('tape'); | ||
| }); | ||
| test('createStreamDecoder - legacy', function(t){ | ||
| var codec = new Codec({ keyEncoding: 'hex' }); | ||
| t.test('keys and values', function(t){ | ||
| var decoder = codec.createStreamDecoder({ | ||
| encoding: 'json', | ||
| keys: true, | ||
| values: true | ||
| }); | ||
| t.deepEqual(decoder(new Buffer('hey'), '"you"'), { | ||
| key: '686579', | ||
| value: 'you' | ||
| }); | ||
| t.end(); | ||
| }); | ||
| t.test('keys', function(t){ | ||
| var decoder = codec.createStreamDecoder({ | ||
| keys: true | ||
| }); | ||
| t.equal(decoder(new Buffer('hey')), '686579'); | ||
| t.end(); | ||
| }); | ||
| t.test('values', function(t){ | ||
| var decoder = codec.createStreamDecoder({ | ||
| encoding: 'hex', | ||
| values: true | ||
| }); | ||
| t.equal(decoder(null, new Buffer('hey')), '686579'); | ||
| t.end(); | ||
| }); | ||
| }); |
+34
-0
@@ -72,1 +72,35 @@ var test = require('tape'); | ||
| test('encode value - legacy', function(t){ | ||
| var codec = new Codec({ encoding: 'hex' }); | ||
| var buf = codec.encodeValue('686579', {}); | ||
| t.equal(buf.toString(), 'hey'); | ||
| buf = codec.encodeValue('686579'); | ||
| t.equal(buf.toString(), 'hey'); | ||
| buf = codec.encodeValue('686579', { | ||
| encoding: 'binary' | ||
| }); | ||
| t.equal(buf.toString(), '686579'); | ||
| t.end(); | ||
| }); | ||
| test('decode value - legacy', function(t){ | ||
| var codec = new Codec({ encoding: 'hex' }); | ||
| var buf = codec.decodeValue(new Buffer('hey'), {}); | ||
| t.equal(buf, '686579'); | ||
| buf = codec.decodeValue(new Buffer('hey')); | ||
| t.equal(buf, '686579'); | ||
| buf = codec.decodeValue(new Buffer('hey'), { | ||
| encoding: 'binary' | ||
| }); | ||
| t.equal(buf.toString(), 'hey'); | ||
| t.end(); | ||
| }); | ||
14209
18.83%379
24.67%