Comparing version 0.0.1 to 0.0.2
16
index.js
@@ -75,5 +75,10 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
var _fn = Util.format('%s.%s.%d_%d', prefix, idx, process.pid, num); | ||
_result[idx].push(_fn); | ||
_result[idx].push({'file' : _fn, 'rows' : 0}); | ||
return fs.createWriteStream(_fn); | ||
var _me = fs.createWriteStream(_fn); | ||
_me.on('error', function (error) { | ||
_complete(iError('StreamWriteError', error.stack)); | ||
}); | ||
return _me; | ||
}; | ||
@@ -115,9 +120,8 @@ /* }}} */ | ||
_writer[idx] = _createWriter(idx); | ||
_wlines[idx] = 0; | ||
_wlines[idx] = 1; | ||
} else { | ||
_wcache[idx] += txt; | ||
_wlines[idx] += 1; | ||
} | ||
_wlines[idx]++; | ||
if (_wcache[idx].length >= _options.bufferSize || _wlines[idx] >= _options.maxLines) { | ||
@@ -128,2 +132,3 @@ _writer[idx].write(_wcache[idx]); | ||
_writer[idx].end(); | ||
(_result[idx][_result[idx].length - 1]).rows = _wlines[idx]; | ||
_writer[idx] = _createWriter(idx); | ||
@@ -142,2 +147,3 @@ _wlines[idx] = 0; | ||
_writer[idx].end(_wcache[idx]); | ||
(_result[idx][_result[idx].length - 1]).rows = _wlines[idx]; | ||
delete _wcache[idx]; | ||
@@ -144,0 +150,0 @@ } |
{ | ||
"name": "filesplit", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Aleafs Zhang (zhangxc83@gmail.com)", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
[![Build Status](https://secure.travis-ci.org/aleafs/filesplit.png?branch=master)](http://travis-ci.org/aleafs/filesplit) | ||
# About # | ||
`filesplit` is a simple and high-speed text file splitor based on Node.js. | ||
Always it has the same results as run command `cut -f x,x $filename[s]` before `split -n $rows` on Linux. | ||
# Install # | ||
```bash | ||
$ npm install filesplit | ||
``` | ||
# Usage # | ||
```javascript | ||
var splitor = require('filesplit'); | ||
var callor = splitor.create([file1, file2, ..., filen], result_prefix); | ||
callor(function (error, result) { | ||
console.log(result); | ||
}); | ||
``` | ||
# Contributors # | ||
@@ -11,21 +29,21 @@ | ||
Copyright (c) 2012 aleafs and other filesplit contributors | ||
Copyright (c) 2012 aleafs and other filesplit contributors | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@@ -57,11 +57,11 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
'thedate=20120623' : [ | ||
__dirname + '/res/output.thedate=20120623.' + process.pid + '_0', | ||
__dirname + '/res/output.thedate=20120623.' + process.pid + '_3', | ||
{'file' : __dirname + '/res/output.thedate=20120623.' + process.pid + '_0', 'rows' : 30}, | ||
{'file' : __dirname + '/res/output.thedate=20120623.' + process.pid + '_3', 'rows' : 12}, | ||
], | ||
'thedate=20120624' : [ | ||
__dirname + '/res/output.thedate=20120624.' + process.pid + '_1', | ||
__dirname + '/res/output.thedate=20120624.' + process.pid + '_4', | ||
{'file' : __dirname + '/res/output.thedate=20120624.' + process.pid + '_1', 'rows' : 30}, | ||
{'file' : __dirname + '/res/output.thedate=20120624.' + process.pid + '_4', 'rows' : 10}, | ||
], | ||
'thedate=20120625' : [ | ||
__dirname + '/res/output.thedate=20120625.' + process.pid + '_2', | ||
{'file' : __dirname + '/res/output.thedate=20120625.' + process.pid + '_2', 'rows' : 28}, | ||
], | ||
@@ -68,0 +68,0 @@ })); |
12849
211
49