first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

5
build/node_modules/filewalker/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.8"
- "0.6"

165
build/node_modules/filewalker/README.md generated vendored Normal file
View File

@@ -0,0 +1,165 @@
Node Filewalker
===============
### Fast and rock-solid asynchronous traversing of directories and files for node.js
[![Build Status](https://secure.travis-ci.org/oleics/node-filewalker.png)](http://travis-ci.org/oleics/node-filewalker)
The filewalker-module for node is designed to provide maximum
reliance paired with maximum throughput/performance and the
ability to throttle that throughput/performance.
### Installation
```npm install filewalker```
### Run the tests
```sh
$ npm test
```
### Usage
Simple directory listing and disk-usage report:
```js
var filewalker = require('filewalker');
filewalker('.')
.on('dir', function(p) {
console.log('dir: %s', p);
})
.on('file', function(p, s) {
console.log('file: %s, %d bytes', p, s.size);
})
.on('error', function(err) {
console.error(err);
})
.on('done', function() {
console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
})
.walk();
```
Calculate md5-hash for every file:
```js
var started = Date.now();
var createHash = require('crypto').createHash,
filewalker = require('./lib/filewalker');
var options = {
maxPending: 10, // throttle handles
};
filewalker('/', options)
.on('stream', function(rs, p, s, fullPath) {
var hash = createHash('md5');
rs.on('data', function(data) {
hash.update(data);
});
rs.on('end', function(data) {
console.log(hash.digest('hex'), (' '+s.size).slice(-16), p);
});
})
.on('error', function(err) {
console.error(err);
})
.on('done', function() {
var duration = Date.now()-started;
console.log('%d ms', duration);
console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
})
.walk();
```
Class Filewalker
----------------
Inherits from [node-fqueue](https://github.com/oleics/node-fqueue)
### Options
```maxPending``` (default: -1)
Maximum asynchronous jobs.
Useful to throttle the number of simultaneous disk-operations.
```maxAttempts``` (default: 3)
Maximum reattempts on error.
Set to 0 to disable reattempts.
Set to -1 for infinite reattempts.
```attemptTimeout``` (default: 5000 ms)
Minimum time to wait before reattempt. In milliseconds.
Useful to let network-drives remount, etc.
```matchRegExp``` (default: null)
A RegExp-instance the path to a file must match in order to
emit a "file" event. Set to ```null``` to emit all paths.
```recursive``` (default: true)
Traverse in a recursive manner.
In case you wish to target only the current directory,
disable this.
### Properties
maxPending
maxAttempts
attemptTimeout
matchRegExp
pending
dirs
files
total
bytes
errors
attempts
streamed
open
detectedMaxOpen
### Methods
walk()
pause()
resume()
### Events
* file
* relative path
* fs.Stats instance
* absolute path
* dir
* relative path
* fs.Stats instance
* absolute path
* stream
* fs.ReadStream instance
* relative path
* fs.Stats instance
* absolute path
* pause
* resume
* done
* error
* instance of Error
Notice: There will be no fs.ReadStream created if no listener
listens to the 'stream'-event.
MIT License
-----------
Copyright (c) Oliver Leics <oliver.leics@gmail.com>
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 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.

26
build/node_modules/filewalker/examples/du.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
var started = Date.now();
var filewalker = require('..');
var options = {
maxPending: -1,
maxAttempts: 3,
attemptTimeout: 3000,
// matchRegExp: /\.(log)$/,
// matchRegExp: /\.(json)|(md)$/,
};
filewalker('/', options)
.on('error', function(err) {
console.error(err);
})
.on('retry', function(func, args, err, r, scope) {
console.log('retry %d / %d %s', r.attempts+1, r.max, args[0]);
})
.on('done', function() {
var duration = Date.now()-started;
console.log('%d ms', duration);
console.log('%d dirs, %d files, %d bytes, %d errors', this.dirs, this.files, this.bytes, this.errors);
})
.walk();

165
build/node_modules/filewalker/examples/fw.js generated vendored Normal file
View File

@@ -0,0 +1,165 @@
var started = Date.now();
var assert = require('assert');
var filewalker = require('..');
var options = {
maxPending: -1,
maxAttempts: 3,
attemptTimeout: 3000,
// matchRegExp: /\.(log)$/,
// matchRegExp: /\.(json)|(md)$/,
};
// var fw = filewalker('./test/examples', options);
// var fw = filewalker('.', options);
// var fw = filewalker('..', options);
// var fw = filewalker('../..', options);
var fw = filewalker('/', options);
// var fw = filewalker('c:/', options);
fw.on('dir', function(p, s, fullPath) {
process.stdout.write('*');
// process.stdout.write('\n');
// console.log('dir ', p);
});
fw.on('file', function(p, s, fullPath) {
process.stdout.write('.');
// process.stdout.write('\n');
// console.log('file ', p);
});
fw.on('stream', function(rs, p, s, fullPath) {
process.stdout.write('~');
// process.stdout.write('\n');
// console.log((' '+thousandSeparator(s.size)).slice(-16), p);
});/* */
fw.on('error', function(err) {
// process.stdout.write('-');
process.stdout.write('\n');
// console.error('ERROR: FW', err.stack||err);
console.log('error ', err);
});
fw.on('pause', function() {
process.stdout.write('P');
// process.stdout.write('\n');
// console.log('PAUSE');
// console.log('%d pending', this.pending);
// console.log('%d queue-length', this.queue.length);
// process.stdout.write('\n');
// var duration = Date.now()-started;
// console.log(formatDuration(duration));
fw.resume();
// setTimeout(function() {
// fw.resume();
// }, 1000);
});
fw.on('resume', function() {
process.stdout.write('R');
// process.stdout.write('\n');
// console.log('RESUME');
// process.stdout.write('\n');
// var duration = Date.now()-started;
// console.log(formatDuration(duration));
fw.pause();
// setTimeout(function() {
// fw.pause();
// }, 3000);
});
fw.on('done', function() {
process.stdout.write('\n');
console.log('DONE');
process.stdout.write('\n');
var duration = Date.now()-started;
console.log(formatDuration(duration));
// console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
// console.log(fw);
process.stdout.write('\n');
console.log('%s', fw.root);
process.stdout.write('\n');
console.log('%s pending', formatInt(fw.pending));
console.log('%s dirs', formatInt(fw.dirs));
console.log('%s files', formatInt(fw.files));
console.log('%s total', formatInt(fw.total));
console.log('%s bytes', formatInt(fw.bytes));
console.log('%s errors', formatInt(fw.errors));
process.stdout.write('\n');
console.log('%s streamed', formatInt(fw.streamed));
console.log('%s detectedMaxOpen', formatInt(fw.detectedMaxOpen));
console.log('%s attempts', formatInt(fw.attempts));
process.stdout.write('\n');
console.dir(fw);
process.stdout.write('\n');
assert.ok(fw.pending === 0);
assert.ok(fw.open === 0);
assert.ok(fw.queue.length === 0);
});
fw.walk();
// fw.pause();
process.on('exit', function() {
});
/*
setInterval(function() {
console.dir(fw);
}, 1000);
*/
function formatDuration(ms) {
var h = 0;
var m = 0;
var s = 0;
if(ms>1000) {
s = Math.floor(ms/1000);
ms = ms - s * 1000;
if(s>60) {
m = Math.floor(s/60);
s = s - m * 60;
if(m>60) {
h = Math.floor(m/60);
m = m - h * 60;
}
}
}
return ('00'+h).slice(-2)
+':'+('00'+m).slice(-2)
+':'+('00'+s).slice(-2)
+'.'+(ms+' ').slice(0,4);
}
function formatInt(n) {
n = thousandSeparator(n);
return (' '+n).slice(-16);
}
function thousandSeparator(n,sep) {
var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'),
sValue=n+'';
if (sep === undefined) {sep=',';}
while(sRegExp.test(sValue)) {
sValue = sValue.replace(sRegExp, '$1'+sep+'$2');
}
return sValue;
}

29
build/node_modules/filewalker/examples/hash.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
var started = Date.now();
var createHash = require('crypto').createHash,
filewalker = require('..');
var options = {
maxPending: 10, // throttle handles
};
filewalker('/', options)
.on('stream', function(rs, p, s, fullPath) {
var hash = createHash('md5');
rs.on('data', function(data) {
hash.update(data);
});
rs.on('end', function(data) {
console.log(hash.digest('hex'), (' '+s.size).slice(-16), p);
});
})
.on('error', function(err) {
console.error(err);
})
.on('done', function() {
var duration = Date.now()-started;
console.log('%d ms', duration);
console.log('%d dirs, %d files, %d bytes', this.dirs, this.files, this.bytes);
})
.walk();

152
build/node_modules/filewalker/lib/filewalker.js generated vendored Normal file
View File

@@ -0,0 +1,152 @@
module.exports = Filewalker;
var fs = require('fs'),
path = require('path'),
util = require('util'),
FunctionQueue = require('fqueue'),
immediately = process.nextTick;
if (global.setImmediate !== undefined) {
immediately = global.setImmediate;
};
var lstat = process.platform === 'win32' ? 'stat' : 'lstat';
function Filewalker(root, options) {
if(!(this instanceof Filewalker)) return new Filewalker(root, options);
FunctionQueue.call(this, options);
var self = this;
this.matchRegExp = null;
this.recursive = true;
options = options || {};
Object.keys(options).forEach(function(k) {
if(self.hasOwnProperty(k)) {
self[k] = options[k];
}
});
this.root = path.resolve(root||'.');
}
util.inherits(Filewalker, FunctionQueue);
Filewalker.prototype._path = function(p) {
if(path.relative) {
return path.relative(this.root, p).split('\\').join('/');
} else {
return p.substr(this.root.length).split('\\').join('/');
}
};
Filewalker.prototype._emitDir = function(p, s, fullPath) {
var self = this,
args = arguments;
this.dirs += 1;
if(this.dirs) { // skip first directroy
this.emit('dir', p, s, fullPath);
}
fs.readdir(fullPath, function(err, files) {
if(err) {
self.error(err, self._emitDir, args);
} else if(self.recursive || !self.dirs) {
files.forEach(function(file) {
self.enqueue(self._stat, [path.join(fullPath, file)]);
});
}
self.done();
});
};
Filewalker.prototype._emitFile = function(p, s, fullPath) {
var self = this;
this.files += 1;
this.bytes += s.size;
this.emit('file', p, s, fullPath);
if(this.listeners('stream').length !== 0) {
this.enqueue(this._emitStream, [p, s, fullPath]);
}
immediately(function() {
self.done();
});
};
Filewalker.prototype._emitStream = function(p, s, fullPath) {
var self = this,
args = arguments;
this.open += 1;
var rs = fs.ReadStream(fullPath);
// retry on any error
rs.on('error', function(err) {
// handle "too many open files" error
if(err.code == 'EMFILE' || (err.code == 'OK' && err.errno === 0)) {
if(self.open-1>self.detectedMaxOpen) {
self.detectedMaxOpen = self.open-1;
}
self.enqueue(self._emitStream, args);
} else {
self.error(err, self._emitStream, args);
}
self.open -= 1;
self.done();
});
rs.on('close', function() {
self.streamed += 1;
self.open -= 1;
self.done();
});
this.emit('stream', rs, p, s, fullPath);
};
Filewalker.prototype._stat = function(p) {
var self = this,
args = arguments;
fs[lstat](p, function(err, s) {
if(err) {
self.error(err, self._stat, args);
} else {
self.total += 1;
if(s.isDirectory()) {
self.enqueue(self._emitDir, [self._path(p), s, p]);
} else {
if(!self.matchRegExp || self.matchRegExp.test(p)) {
self.enqueue(self._emitFile, [self._path(p), s, p]);
}
}
}
self.done();
});
};
Filewalker.prototype.walk = function() {
this.dirs = -1;
this.files = 0;
this.total = -1;
this.bytes = 0;
this.streamed = 0;
this.open = 0;
this.detectedMaxOpen = -1;
this.queue = [];
this.start(this._stat, [this.root]);
return this;
};

60
build/node_modules/filewalker/package.json generated vendored Normal file
View File

@@ -0,0 +1,60 @@
{
"_from": "filewalker@0.1.3",
"_id": "filewalker@0.1.3",
"_inBundle": false,
"_integrity": "sha1-1jv52BO6NTRLgYJ0eCT2/3VL9MU=",
"_location": "/filewalker",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "filewalker@0.1.3",
"name": "filewalker",
"escapedName": "filewalker",
"rawSpec": "0.1.3",
"saveSpec": null,
"fetchSpec": "0.1.3"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/filewalker/-/filewalker-0.1.3.tgz",
"_shasum": "d63bf9d813ba35344b8182747824f6ff754bf4c5",
"_spec": "filewalker@0.1.3",
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
"author": {
"name": "Oliver Leics",
"email": "oliver.leics@gmail.com"
},
"bugs": {
"url": "https://github.com/oleics/node-filewalker/issues"
},
"bundleDependencies": false,
"contributors": [],
"dependencies": {
"fqueue": "0.0.x"
},
"deprecated": false,
"description": "Fast and rock-solid asynchronous traversing of directories and files for node.js",
"devDependencies": {
"mocha": "1.0.x"
},
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">= 0.4.x"
},
"homepage": "https://github.com/oleics/node-filewalker#readme",
"main": "./lib/filewalker",
"name": "filewalker",
"repository": {
"type": "git",
"url": "git+https://github.com/oleics/node-filewalker.git"
},
"scripts": {
"test": "mocha -R spec"
},
"version": "0.1.3"
}

372
build/node_modules/filewalker/test/basic-test.js generated vendored Normal file
View File

@@ -0,0 +1,372 @@
var assert = require('assert');
var filewalker = require('..');
var examplesDir = require('path').resolve(__dirname, 'examples');
var examplesFile = require('path').resolve(__filename);
var examplesNumOfDirs = 1;
var examplesNumOfFiles = 2;
var examplesNumOfBytes = 6;
function reallyReadTheReadStream(rs) {
// Since NodeJS v0.10 and Streams2 we must subscribe to the data-event of
// the file, or the end/close-event will not happen.
rs.on('data', function(){});
}
describe('Filewalker', function() {
describe('Basics', function() {
it('Exports one function', function() {
assert.ok(filewalker instanceof Function);
});
it('That function creates an instances of a filewalker-class', function() {
assert.ok(filewalker() instanceof Object);
});
});
describe('Instances of a filewalker-class', function() {
var fw;
beforeEach(function() {
fw = filewalker(examplesDir);
});
afterEach(function() {
fw = null;
});
it('are instances of events.EventEmitter too', function() {
assert.ok(fw instanceof require('events').EventEmitter);
});
it('are instances of fqueue', function() {
assert.ok(fw instanceof require('fqueue'));
});
it('should have a .maxPending property <number>', function() {
assert.ok(fw.maxPending!=null);
assert.strictEqual(typeof fw.maxPending, 'number');
});
it('should have a .maxAttempts property <number>', function() {
assert.ok(fw.maxAttempts!=null);
assert.strictEqual(typeof fw.maxAttempts, 'number');
});
it('should have a .attemptTimeout property <number>', function() {
assert.ok(fw.attemptTimeout!=null);
assert.strictEqual(typeof fw.attemptTimeout, 'number');
});
it('should have a .matchRegExp property <number>', function() {
assert.strictEqual(fw.matchRegExp, null);
});
it('should have a .recursive property <boolean>', function() {
assert.strictEqual(fw.recursive, true);
});
it('should have a .walk() method', function() {
assert.ok(fw.walk instanceof Function);
});
it('should have a .pause() method', function() {
assert.ok(fw.pause instanceof Function);
});
it('should have a .resume() method', function() {
assert.ok(fw.resume instanceof Function);
});
it('should have a .on() method', function() {
assert.ok(fw.on instanceof Function);
});
describe('properties after a call to .walk()', function() {
it('.pending must be 0', function(done) {
fw.on('done', function() {
assert.ok(fw.pending!=null);
assert.strictEqual(typeof fw.pending, 'number');
assert.strictEqual(fw.pending, 0);
});
fw.on('done', done);
fw.walk();
});
it('.paused must be false', function(done) {
fw.on('done', function() {
assert.ok(fw.paused!=null);
assert.strictEqual(typeof fw.paused, 'boolean');
assert.strictEqual(fw.paused, false);
});
fw.on('done', done);
fw.walk();
});
it('.dirs must be '+examplesNumOfDirs, function(done) {
fw.on('done', function() {
assert.ok(fw.dirs!=null);
assert.strictEqual(typeof fw.dirs, 'number');
assert.strictEqual(fw.dirs, examplesNumOfDirs);
});
fw.on('done', done);
fw.walk();
});
it('.files must be '+examplesNumOfFiles, function(done) {
fw.on('done', function() {
assert.ok(fw.files!=null);
assert.strictEqual(typeof fw.files, 'number');
assert.strictEqual(fw.files, examplesNumOfFiles);
});
fw.on('done', done);
fw.walk();
});
it('.total must be '+(examplesNumOfFiles+examplesNumOfDirs), function(done) {
fw.on('done', function() {
assert.ok(fw.total!=null);
assert.strictEqual(typeof fw.total, 'number');
assert.strictEqual(fw.total, (examplesNumOfFiles+examplesNumOfDirs));
});
fw.on('done', done);
fw.walk();
});
it('.bytes must be '+examplesNumOfBytes, function(done) {
fw.on('done', function() {
assert.ok(fw.bytes!=null);
assert.strictEqual(typeof fw.bytes, 'number');
assert.strictEqual(fw.bytes, examplesNumOfBytes);
});
fw.on('done', done);
fw.walk();
});
it('.errors must be 0', function(done) {
fw.on('done', function() {
assert.ok(fw.errors!=null);
assert.strictEqual(typeof fw.errors, 'number');
assert.strictEqual(fw.errors, 0);
});
fw.on('done', done);
fw.walk();
});
it('.attempts must be 0', function(done) {
fw.on('done', function() {
assert.ok(fw.attempts!=null);
assert.strictEqual(typeof fw.attempts, 'number');
assert.strictEqual(fw.attempts, 0);
});
fw.on('done', done);
fw.walk();
});
it('.streamed must be 0 if no listener for stream-event', function(done) {
fw.on('done', function() {
assert.ok(fw.streamed!=null);
assert.strictEqual(typeof fw.streamed, 'number');
assert.strictEqual(fw.streamed, 0);
});
fw.on('done', done);
fw.walk();
});
it('.streamed must be '+examplesNumOfFiles+' if listener for stream-event', function(done) {
fw.on('stream', function(rs){
reallyReadTheReadStream(rs);
});
fw.on('done', function() {
assert.ok(fw.streamed!=null);
assert.strictEqual(typeof fw.streamed, 'number');
assert.strictEqual(fw.streamed, examplesNumOfFiles);
});
fw.on('done', done);
fw.walk();
});
it('.open must be 0 if listener for stream-event', function(done) {
fw.on('stream', function(rs){
reallyReadTheReadStream(rs);
});
fw.on('done', function() {
assert.ok(fw.open!=null);
assert.strictEqual(typeof fw.open, 'number');
assert.strictEqual(fw.open, 0);
});
fw.on('done', done);
fw.walk();
});
it('.detectedMaxOpen must be -1 if listener for stream-event', function(done) {
fw.on('stream', function(rs){
reallyReadTheReadStream(rs);
});
fw.on('done', function() {
assert.ok(fw.detectedMaxOpen!=null);
assert.strictEqual(typeof fw.detectedMaxOpen, 'number');
assert.strictEqual(fw.detectedMaxOpen, -1);
});
fw.on('done', done);
fw.walk();
});
});
describe('events after .walk()', function() {
it('"done" event with 0 arguments', function(done) {
fw.on('done', function() {
assert.strictEqual(arguments.length, 0);
done();
});
fw.walk();
});
it('"dir" event with 3 arguments', function(done) {
var fired = 0;
fw.on('dir', function(p, s, fullPath) {
assert.strictEqual(arguments.length, 3);
assert.ok(p instanceof String || typeof p === 'string', 'Type or instance of string');
assert.ok(s instanceof require('fs').Stats, 'Instance of fs.Stats');
assert.ok(fullPath instanceof String || typeof fullPath === 'string', 'Type or instance of string');
fired += 1;
});
fw.on('done', function() {
assert.strictEqual(fired, examplesNumOfDirs);
});
fw.on('done', done);
fw.walk();
});
it('"file" event with 3 arguments', function(done) {
var fired = 0;
fw.on('file', function(p, s, fullPath) {
assert.strictEqual(arguments.length, 3);
assert.ok(p instanceof String || typeof p === 'string', 'Type or instance of string');
assert.ok(s instanceof require('fs').Stats, 'Instance of fs.Stats');
assert.ok(fullPath instanceof String || typeof fullPath === 'string', 'Type or instance of string');
fired += 1;
});
fw.on('done', function() {
assert.strictEqual(fired, examplesNumOfFiles);
});
fw.on('done', done);
fw.walk();
});
it('"stream" event with 4 arguments', function(done) {
var fired = 0;
fw.on('stream', function(rs, p, s, fullPath) {
assert.strictEqual(arguments.length, 4);
assert.ok(rs instanceof require('fs').ReadStream, 'Instance of fs.ReadStream');
assert.ok(p instanceof String || typeof p === 'string', 'Type or instance of string');
assert.ok(s instanceof require('fs').Stats, 'Instance of fs.Stats');
assert.ok(fullPath instanceof String || typeof fullPath === 'string', 'Type or instance of string');
fired += 1;
reallyReadTheReadStream(rs);
});
fw.on('done', function() {
assert.strictEqual(fired, examplesNumOfFiles);
});
fw.on('done', done);
fw.walk();
});
it('"pause" event with 0 arguments', function(done) {
var fired = 0;
fw.on('pause', function() {
assert.strictEqual(arguments.length, 0);
fw.resume();
fired += 1;
});
fw.on('done', function() {
assert.strictEqual(fired, 1);
});
fw.on('done', done);
fw.walk();
fw.pause();
});
it('"resume" event with 0 arguments', function(done) {
var fired = 0;
fw.on('pause', function() {
fw.resume();
});
fw.on('resume', function() {
assert.strictEqual(arguments.length, 0);
fired += 1;
});
fw.on('done', function() {
assert.strictEqual(fired, 1);
});
fw.on('done', done);
fw.walk();
fw.pause();
});
});
describe('.pause() and .resume()', function() {
it('"done" event must fire if they play ping-pong', function(done) {
var fired = 0;
fw.on('pause', function() {
fw.resume();
fired += 1;
});
fw.on('resume', function() {
fw.pause();
fired += 1;
});
fw.on('done', function() {
assert.ok(fired > 1);
});
fw.on('done', done);
fw.walk();
fw.pause();
});
});
});
describe('feature: filewalker on a path to a file', function() {
var fw;
before(function() {
fw = filewalker(examplesFile);
});
after(function() {
fw = null;
});
it('emits the "stream", "file" and "done" event', function(done) {
fw.on('dir', function() {
assert.ok(false, '"dir" event must not fire');
});
fw.on('file', function(p, s, fullPath) {
assert.strictEqual(arguments.length, 3);
assert.ok(p instanceof String || typeof p === 'string', 'Type or instance of string');
assert.ok(s instanceof require('fs').Stats, 'Instance of fs.Stats');
assert.ok(fullPath instanceof String || typeof fullPath === 'string', 'Type or instance of string');
});
fw.on('stream', function(rs, p, s, fullPath) {
assert.strictEqual(arguments.length, 4);
assert.ok(rs instanceof require('fs').ReadStream, 'Instance of fs.ReadStream');
assert.ok(p instanceof String || typeof p === 'string', 'Type or instance of string');
assert.ok(s instanceof require('fs').Stats, 'Instance of fs.Stats');
assert.ok(fullPath instanceof String || typeof fullPath === 'string', 'Type or instance of string');
reallyReadTheReadStream(rs);
});
fw.on('done', function() {
assert.strictEqual(arguments.length, 0);
});
fw.on('done', done);
fw.walk();
});
});
describe('feature: non-recursive walking', function() {
var fw;
before(function() {
fw = filewalker(examplesDir, {recursive: false});
});
after(function() {
fw = null;
});
it('"done" event without recursive', function(done) {
fw.on('done', function() {
// it could be nicer to check the amount using fs on examplesDir
// this works, though, given the structure of /examples doesn't change
assert.strictEqual(this.files + this.dirs, 2);
done();
});
fw.walk();
});
});
});

1
build/node_modules/filewalker/test/examples/foo/bar generated vendored Normal file
View File

@@ -0,0 +1 @@
...

1
build/node_modules/filewalker/test/examples/test generated vendored Normal file
View File

@@ -0,0 +1 @@
...