diff --git a/index.js b/index.js index 1ca3520..d744a8c 100644 --- a/index.js +++ b/index.js @@ -110,6 +110,9 @@ exports.create = function (flist, prefix, options) { reader.on('error', function (error) { _complete(iError('StreamReadError', error.stack)); }); + reader.on('end', function () { + _readfile(flist.shift()); + }); var _tail = ''; reader.on('data', function (data) { @@ -142,10 +145,6 @@ exports.create = function (flist, prefix, options) { } } }); - - reader.on('end', function () { - _readfile(flist.shift()); - }); }; return function (callback) { diff --git a/test/filesplit.test.js b/test/filesplit.test.js index f3bf633..9bc3f83 100644 --- a/test/filesplit.test.js +++ b/test/filesplit.test.js @@ -40,6 +40,7 @@ describe('file split', function () { }); /* }}} */ + /* {{{ should_file_split_works_fine() */ it('should_file_split_works_fine', function (done) { var _input = [__dirname + '/res/test_input_1.txt', __dirname + '/res/test_input_2.txt']; var caller = splitor.create(_input, __dirname + '/res/output', { @@ -50,14 +51,24 @@ describe('file split', function () { 'fields' : [1,0,4,3], }); caller(function (error, result) { + should.ok(!error); + JSON.stringify(result).should.eql(JSON.stringify({ + 'thedate=20120623' : [ + __dirname + '/res/output.thedate=20120623.' + process.pid + '_0', + __dirname + '/res/output.thedate=20120623.' + process.pid + '_3', + ], + 'thedate=20120624' : [ + __dirname + '/res/output.thedate=20120624.' + process.pid + '_1', + __dirname + '/res/output.thedate=20120624.' + process.pid + '_4', + ], + 'thedate=20120625' : [ + __dirname + '/res/output.thedate=20120625.' + process.pid + '_2', + ], + })); done(); }); }); + /* }}} */ - /* - afterEach(function (done) { - cleanOutput(done); - }); -*/ });