blob: 98e852d1340932c659eee03b66d105b6c09cd76c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  | 
var spawn = require('child_process').spawn;
var find = spawn('find',[process.argv[2]||'./']);
var fs = require('fs');
var buf = '',count = 0;
handleBuf = function(data){
	buf += data;
	if(buf.length >= 1024) {
		var lines = buf.split("\n");
		buf = lines.pop();//last line my not be complete
		count += lines.length;
		process.stdout.write(lines.join("\n")+"\n");
	}
};
find.stdout.on('data',function(data){
	//buf += data.toString();
	handleBuf(data)
	//process.stdout.write(data.toString());
});
find.on('end',function(){
	handleBuf("\n");
	console.log('found '+count+' files');
	console.log('ended');
});
find.stdin.end();
 
  |