root / HServer / 00.Server / 00.Program / node_modules / streamsearch / README.md
이력 | 보기 | 이력해설 | 다운로드 (2.25 KB)
1 | 39 | HKM | Description |
---|---|---|---|
2 | =========== |
||
3 | |||
4 | streamsearch is a module for [node.js](http://nodejs.org/) that allows searching a stream using the Boyer-Moore-Horspool algorithm. |
||
5 | |||
6 | This module is based heavily on the Streaming Boyer-Moore-Horspool C++ implementation by Hongli Lai [here](https://github.com/FooBarWidget/boyer-moore-horspool). |
||
7 | |||
8 | |||
9 | Requirements |
||
10 | ============ |
||
11 | |||
12 | * [node.js](http://nodejs.org/) -- v0.8.0 or newer |
||
13 | |||
14 | |||
15 | Installation |
||
16 | ============ |
||
17 | |||
18 | npm install streamsearch |
||
19 | |||
20 | Example |
||
21 | ======= |
||
22 | |||
23 | ```javascript |
||
24 | var StreamSearch = require('streamsearch'), |
||
25 | inspect = require('util').inspect; |
||
26 | |||
27 | var needle = new Buffer([13, 10]), // CRLF |
||
28 | s = new StreamSearch(needle), |
||
29 | chunks = [ |
||
30 | new Buffer('foo'), |
||
31 | new Buffer(' bar'), |
||
32 | new Buffer('\r'), |
||
33 | new Buffer('\n'), |
||
34 | new Buffer('baz, hello\r'), |
||
35 | new Buffer('\n world.'), |
||
36 | new Buffer('\r\n Node.JS rules!!\r\n\r\n') |
||
37 | ]; |
||
38 | s.on('info', function(isMatch, data, start, end) { |
||
39 | if (data) |
||
40 | console.log('data: ' + inspect(data.toString('ascii', start, end))); |
||
41 | if (isMatch) |
||
42 | console.log('match!'); |
||
43 | }); |
||
44 | for (var i = 0, len = chunks.length; i < len; ++i) |
||
45 | s.push(chunks[i]); |
||
46 | |||
47 | // output: |
||
48 | // |
||
49 | // data: 'foo' |
||
50 | // data: ' bar' |
||
51 | // match! |
||
52 | // data: 'baz, hello' |
||
53 | // match! |
||
54 | // data: ' world.' |
||
55 | // match! |
||
56 | // data: ' Node.JS rules!!' |
||
57 | // match! |
||
58 | // data: '' |
||
59 | // match! |
||
60 | ``` |
||
61 | |||
62 | |||
63 | API |
||
64 | === |
||
65 | |||
66 | Events |
||
67 | ------ |
||
68 | |||
69 | * **info**(< _boolean_ >isMatch[, < _Buffer_ >chunk, < _integer_ >start, < _integer_ >end]) - A match _may_ or _may not_ have been made. In either case, a preceding `chunk` of data _may_ be available that did not match the needle. Data (if available) is in `chunk` between `start` (inclusive) and `end` (exclusive). |
||
70 | |||
71 | |||
72 | Properties |
||
73 | ---------- |
||
74 | |||
75 | * **maxMatches** - < _integer_ > - The maximum number of matches. Defaults to Infinity. |
||
76 | |||
77 | * **matches** - < _integer_ > - The current match count. |
||
78 | |||
79 | |||
80 | Functions |
||
81 | --------- |
||
82 | |||
83 | * **(constructor)**(< _mixed_ >needle) - Creates and returns a new instance for searching for a _Buffer_ or _string_ `needle`. |
||
84 | |||
85 | * **push**(< _Buffer_ >chunk) - _integer_ - Processes `chunk`. The return value is the last processed index in `chunk` + 1. |
||
86 | |||
87 | * **reset**() - _(void)_ - Resets internal state. Useful for when you wish to start searching a new/different stream for example. |