1 | var Parser = require("./Parser.js");
|
2 |
|
3 | var Stream = function(options){
|
4 | Parser.call(this, new cbs(this), options);
|
5 | };
|
6 |
|
7 | require("util").inherits(Stream, require("stream").Stream);
|
8 |
|
9 |
|
10 |
|
11 | Object.getOwnPropertyNames(Parser.prototype).forEach(function(name){
|
12 | Stream.prototype[name] = Parser.prototype[name];
|
13 | });
|
14 |
|
15 | Stream.prototype.writable = true;
|
16 | Stream.prototype.readable = true;
|
17 |
|
18 | var cbs = function(scope){
|
19 | this.scope = scope;
|
20 | };
|
21 |
|
22 | cbs.prototype = {
|
23 | oncdataend: function(){
|
24 | this.scope.emit("cdataend");
|
25 | },
|
26 | oncdatastart: function(){
|
27 | this.scope.emit("cdatastart");
|
28 | },
|
29 | onclosetag: function(name){
|
30 | this.scope.emit("closetag", name);
|
31 | },
|
32 | oncomment: function(text){
|
33 | this.scope.emit("comment", text);
|
34 | },
|
35 | oncommentend: function(){
|
36 | this.scope.emit("commentend");
|
37 | },
|
38 | onerror: function(err){
|
39 | this.scope.emit("error", err);
|
40 | },
|
41 | onopentag: function(name, attribs, type){
|
42 | this.scope.emit("opentag", name, attribs, type);
|
43 | },
|
44 | onopentagname: function(name){
|
45 | this.scope.emit("opentagname", name);
|
46 | },
|
47 | onattribute: function(name, value){
|
48 | this.scope.emit("attribute", name, value);
|
49 | },
|
50 | onprocessinginstruction: function(name, data){
|
51 | this.scope.emit("processinginstruction", name, data);
|
52 | },
|
53 | onend: function(){
|
54 | this.scope.emit("end");
|
55 | },
|
56 | onreset: function(){
|
57 | this.scope.emit("reset");
|
58 | },
|
59 | ontext: function(text){
|
60 | this.scope.emit("text", text);
|
61 |
|
62 |
|
63 | }
|
64 | };
|
65 |
|
66 | module.exports = Stream; |
\ | No newline at end of file |