diff --git a/.travis.yml b/.travis.yml index 994e275..20fd86b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ language: node_js node_js: - - 0.9 - 0.10 diff --git a/README.md b/README.md index bcc6997..1e49db0 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ### Tools for parsing, filtering and creating Redis RDB files -[![Build Status](https://travis-ci.org/codeaholics/node-rdb-tools.png?branch=master)](https://travis-ci.org/codeaholics/node-rdb-tools) +[![Build Status](https://travis-ci.org/codeaholics/node-rdb-tools.png?branch=master)](https://travis-ci.org/codeaholics/node-rdb-tools) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/codeaholics/node-rdb-tools/trend.png)](https://bitdeli.com/free "Bitdeli Badge") This module currently provides: * an [RDB parser](#parser) - a "streams2" [transformer](http://nodejs.org/api/stream.html#stream_class_stream_transform) which understands Redis RDB files and produces objects representing the keys and values * an [RDB writer](#writer) - a transformer which consumes the objects produced by the [parser](#parser) and produces a Redis RDB file -* a ["protocol emitter"](#protocol-emitter) - a transformer which takes arrays of Redis commands and produces raw Redis network protocol +* a ["protocol emitter"](#protocol-emitter) - a transformer which takes arrays of Redis commands and produces raw Redis network protocol suitable for piping into `redis-cli --pipe` In future it will also provide tools for modifying RDB files - for example deleting keys, moving keys to different spaces, merging/splitting RDB files, etc. @@ -104,7 +104,7 @@ This object is produced when a "database" record is found. This indicates that a ```javascript { type: 'database', - database: , + number: , offset: } ``` diff --git a/binding.gyp b/binding.gyp index 33d8703..5e8245c 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,7 @@ { "target_name": "Crc64", "sources": [ - "src/crc64.c", + "src/crc-64-jones.c", "src/Crc64.cc" ] } diff --git a/lib/parser.js b/lib/parser.js index efb0c91..0d1a8cf 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -31,7 +31,9 @@ function Parser(options) { return new Parser(options); } - Transform.call(this, {objectMode: true}); + Transform.call(this); + this._writableState.objectMode = false; + this._readableState.objectMode = true; options = options || {}; diff --git a/lib/protocol-emitter.js b/lib/protocol-emitter.js index 7dd2997..e83b5e3 100644 --- a/lib/protocol-emitter.js +++ b/lib/protocol-emitter.js @@ -25,7 +25,9 @@ function ProtocolEmitter(options) { return new ProtocolEmitter(options); } - Transform.call(this, {objectMode: true}); + Transform.call(this); + this._writableState.objectMode = true; + this._readableState.objectMode = false; options = options || {}; @@ -42,9 +44,9 @@ function ProtocolEmitter(options) { } function handleArray(obj) { - var bufs = []; + var bufs = []; - bufs.push(new Buffer('*' + obj.length, 'ascii'));; + bufs.push(new Buffer('*' + obj.length, 'ascii')); bufs.push(crlf); for (var i = 0; i < obj.length; i++) { var value = new Buffer(obj[i], 'utf8'); diff --git a/lib/writer.js b/lib/writer.js index b01cdfb..4db310d 100644 --- a/lib/writer.js +++ b/lib/writer.js @@ -27,7 +27,9 @@ function Writer(options) { return new Writer(options); } - Transform.call(this, {objectMode: true}); + Transform.call(this); + this._writableState.objectMode = true; + this._readableState.objectMode = false; options = options || {}; diff --git a/package.json b/package.json index 11fafdd..5c8756e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdb-tools", - "version": "0.0.8", + "version": "0.1.1", "description": "Redis RDB parsing, filtering and creating tools", "author": "Danny Yates ", "licenses": [ diff --git a/src/crc64.c b/src/crc-64-jones.c similarity index 100% rename from src/crc64.c rename to src/crc-64-jones.c diff --git a/test/dumps/utf8.rdb b/test/dumps/utf8.rdb new file mode 100644 index 0000000..4cef203 Binary files /dev/null and b/test/dumps/utf8.rdb differ diff --git a/test/parser.js b/test/parser.js index ab62a28..c81c8e9 100644 --- a/test/parser.js +++ b/test/parser.js @@ -277,6 +277,13 @@ describe('Parser', function() { done(); }) }); + + it('should handle UTF-8', function(done) { + load('utf8.rdb', function(data) { + assert.equal(data.allKeys[0]['\u00A3'].value, '\u00A9'); + done(); + }) + }); }) function load(database, cb, errback) { diff --git a/test/writer.js b/test/writer.js index f0380c0..9d6fa0b 100644 --- a/test/writer.js +++ b/test/writer.js @@ -18,13 +18,17 @@ var Parser = require('../rdb-tools').Parser, fs = require('fs'), Writable = require('stream').Writable, Transform = require('stream').Transform, + BufferList = require('bl'), _ = require('underscore'); describe('Writer', function() { describe('should round-trip all parser test files', function() { _.each(fs.readdirSync('test/dumps'), function(f) { if (!f.match(/error/)) { - it(f, roundTripTest.bind(null, f)); + it(f, function(done) { + this.test.slow(125); + roundTripTest(f, done); + }); } }); }); @@ -42,7 +46,36 @@ describe('Writer', function() { }); }); - it.skip('should handle UTF-8'); + it('should handle UTF-8', function(done) { + var writer = new Writer(), + bl = new BufferList(function(err, data) { + assert.equal(data.get(13), 0xC2); + assert.equal(data.get(14), 0xA3); + assert.equal(data.get(16), 0xC2); + assert.equal(data.get(17), 0xA9); + done(); + }); + + writer.pipe(bl); + + writer.write({ + type: 'header', + version: 6 + }); + + writer.write({ + type: 'database', + number: 0 + }); + + writer.end({ + type: 'key', + rtype: 'string', + database: 0, + key: '\u00A3', + value: '\u00A9' + }); + }); }); function simpleErrorTest(obj, done) {