Permalink
Newer
Older
100644 134 lines (104 sloc) 6.06 KB
May 31, 2011
1
# Stalker
May 31, 2011
2
May 31, 2011
3
Stalker is a utility to watch a directory tree for incoming files. When if finds
4
one, it will fire off a callback function __OF YOUR CHOICE!__
May 31, 2011
5
6
It should be smart enough to handle multiple files/folders being dropped into the
Jun 8, 2011
7
directory being stalked.
May 31, 2011
8
May 31, 2011
9
## Installation
10
May 31, 2011
11
$ npm install stalker
May 31, 2011
12
May 31, 2011
13
## How to use
14
15
var stalker = require('stalker');
16
17
stalker.watch('some_directory', function (err, file) {
18
console.log('I saw a file. It was going like this: ' + file);
19
});
20
21
## Options
23
You can pass in a buffer time in milliseconds to make stalker batch up
24
the files and send them back in an array. The timer only starts when a new file
25
drops.
26
27
stalker.watch('./example', {buffer: 5000}, function(err, f) {
28
f.forEach(function _forEach(_f) {
29
console.log('I see ' + _f);
30
});
31
});
32
33
Setting recurse to false will keep stalker for walking down directories.
34
35
stalker.watch('./example', {recurse: false}, function(err, f) {
36
console.log('I see ' + _f);
37
});
38
39
Setting strict to true will make stalker return for modified files.
40
*This has unpredictable behavior on windows/OSX. I have only used it
41
on Linux*
42
43
stalker.watch('./example', {strict: true}, function(err, f) {
44
console.log('I see ' + _f);
45
});
46
47
Stalker will also take a second callback that will be fired when files are removed:
48
49
stalker.watch('./example', function(err, f) {
50
console.log('Added: ' + f);
51
}, function(err, f) {
52
console.log('Removed: ' + f);
53
});
55
The removal callback also works in batch mode.
Jun 8, 2011
57
## Running tests
58
59
I couldn't handle vows.js anymore. I ripped it out. Will replace with something
60
else in the future. For now, run example/*.js and play around adding and
61
removing files from the example directory:
Jun 8, 2011
62
63
node example/test.js
64
May 31, 2011
65
## License
66
67
(The MIT License)
68
69
Copyright (c) 2011 Justin Slattery (Justin.Slattery@fzysqr.com)
May 31, 2011
70
71
Permission is hereby granted, free of charge, to any person obtaining
72
a copy of this software and associated documentation files (the
73
'Software'), to deal in the Software without restriction, including
74
without limitation the rights to use, copy, modify, merge, publish,
75
distribute, sublicense, and/or sell copies of the Software, and to
76
permit persons to whom the Software is furnished to do so, subject to
77
the following conditions:
78
79
The above copyright notice and this permission notice shall be
80
included in all copies or substantial portions of the Software.
81
82
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
83
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
May 31, 2011
89
90
## Gir
May 31, 2011
91
:/::-.`
92
.o-```.:+o++//-
93
++`````--------/o++:`
94
.o.````.-------------:++/:---------.`
95
++````.-------------------+oo+++++//+oso/:.
96
://o: `s-````-----------------------:oo- `-:+o+.--`
97
-+/::shy:-s````.-------:++++/:-------------+o: +/:/o`
98
/+::::hhhhy````-----:+++/:::::+++:------------/s- .::/`
99
o/::::ohhhh+``.----/o+::::::::::::+o:------------+o`
100
o/::::+dhhhd.`.---:o+::::::::::::::::s:------------:s/
101
+/::::/hhhhhs`----/o::::::::::::::::::/y-------------:ss`
102
-+::::/hhhhhh.----/o::::::::::::::::::::m+-----------/oooh-
103
o::::+hhhhhy.-----s::::::::::::::::::::sho---------:/oooooy/
104
.o:::shhhhho`-----:o:::::::::::::::::::odd/--------:+oooooooy/
105
.o/ohhhhhy:`.-----:s:::::::::::::::::/yhho--------/oooooooooy/
106
`------y-``-------o+::::::::::::::/shhh+-------:+ooooooooy+`
107
y``.:oo+:---/o/:::::::::/oyhhhs:-------/ooooooooys.
108
y``-y.o.+o----/ossooosyhhhhyo:-------:+ooooooosy-
109
y``++-/`-Nh------/+osssoo/:--------:/ooooooooy:
110
o-`-sNmhNMMo----------------------/+oooooooy+
111
`y`.-NMMMMMm--------------------/+oooooooyo`
112
:+`/MMMMMMh------------------/+oooooooyo`
113
:o.smNNds:---------------:/+oooooooyo.
114
.o/-------------------:/+oooooooy+`
115
.+o:-------------:/+oooooooss/`
116
:+o+:-----://+oooooooys+.
117
`:/+osyssoossyysohdo/`
118
`.----.` ./sds/.
119
.:oymho/:///`
120
`-`+-:sh:-o-:::/s
121
.o+ooos:/s/s:++:+s
122
+h/:yho+/:s/sooyd`
123
.s.:/ooss+yoy
124
/+-////o+soh`
125
`://o+.s/:--:/oyo`
126
.+++:s/. .//+y/:`
127
/+.-/y- :o+h
128
y`-:oy+ //--os/`
129
//+oysy` //.-:+oys+-
130
/+/++oyso:
131
`.`
132
May 31, 2011
133