Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WRITER: First failing tests for writer

  • Loading branch information...
commit 295c1fff25d4abe9c1f97a70b080e490b383dea6 1 parent 125b866
Danny Yates authored
Showing with 107 additions and 0 deletions.
  1. +48 −0 lib/writer.js
  2. +1 −0  rdb-tools.js
  3. +58 −0 test/writer.js
48 lib/writer.js
View
@@ -0,0 +1,48 @@
+// Copyright 2013 Danny Yates
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var Transform = require('stream').Transform,
+ lzf = require('lzf'),
+ util = require('util'),
+ bufferEqual = require('buffer-equal'),
+ Int64 = require('int64-native'),
+ Crc64 = require('../build/Release/Crc64.node').Crc64;
+
+exports = module.exports = Writer;
+
+util.inherits(Writer, Transform);
+
+function Writer(options) {
+ if (!(this instanceof Writer)) {
+ return new Writer(options);
+ }
+
+ Transform.call(this, {objectMode: true});
+
+ options = options || {};
+
+ var self = this;
+ var currentDatabase = 0;
+ var encoding = options.encoding || 'utf8';
+ var crc = new Crc64();
+ var emptyCrc = new Buffer(8);
+ var expectedNext = 'header';
+
+ emptyCrc.fill(0);
+
+ self._transform = function(obj, encoding, cb) {
+ // TODO: implement me!
+ cb();
+ }
+}
1  rdb-tools.js
View
@@ -14,5 +14,6 @@
exports = module.exports = {
Parser: require('./lib/parser'),
+ Writer: require('./lib/writer'),
ProtocolEmitter: require('./lib/protocol-emitter')
}
58 test/writer.js
View
@@ -0,0 +1,58 @@
+// Copyright 2013 Danny Yates
+
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var Parser = require('../rdb-tools').Parser,
+ Writer = require('../rdb-tools').Writer,
+ assert = require('chai').assert,
+ fs = require('fs'),
+ Writable = require('stream').Writable,
+ Transform = require('stream').Transform,
+ _ = require('underscore');
+
+describe('Writer', function() {
+ describe('should round-trip', function() {
+ _.each(fs.readdirSync('test/dumps'), function(f) {
+ it(f, roundTrip.bind(null, f));
+ });
+ })
+});
+
+function roundTrip(f, done) {
+ var inputStream = fs.createReadStream('test/dumps/' + f),
+ parser = new Parser(),
+ inputCaptor = new Transform({objectMode: true}),
+ writer = new Writer(),
+ reparser = new Parser(),
+ outputCaptor = new Writable({objectMode: true}),
+ inputCaptives = [],
+ outputCaptives = [];
+
+ inputCaptor._transform = function(obj, encoding, cb) {
+ inputCaptives.push(obj);
+ this.push(obj);
+ cb();
+ }
+
+ outputCaptor._write = function(obj, encoding, cb) {
+ outputCaptives.push(obj);
+ cb();
+ }
+
+ outputCaptor.on('finish', function() {
+ // TODO: check the input and output captive match
+ done('not yet testing');
+ });
+
+ inputStream.pipe(parser).pipe(inputCaptor).pipe(writer).pipe(reparser).pipe(outputCaptor);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.