[Pkg-javascript-commits] [node-expat] 119/371: added stream support

Jonas Smedegaard dr at jones.dk
Sun Feb 28 09:59:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-expat.

commit 6559f0c2ab8e67a6dc28fb2418711ebcf51c5f88
Author: Tom Hughes-Croucher <tom.croucher at gmail.com>
Date:   Thu Dec 29 17:43:52 2011 -0800

    added stream support
---
 lib/node-expat.js | 80 ++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 55 insertions(+), 25 deletions(-)

diff --git a/lib/node-expat.js b/lib/node-expat.js
index cad557f..7d43305 100644
--- a/lib/node-expat.js
+++ b/lib/node-expat.js
@@ -1,42 +1,72 @@
 var EventEmitter = require('events').EventEmitter;
 var util = require('util');
+var Stream = require('stream').Stream;
+
 try {
-	var expat = require('../build/Release/node-expat');
+  var expat = require('../build/Release/node-expat');
 } catch(e) {
-	var expat = require('../build/default/node-expat');
+  var expat = require('../build/default/node-expat');
 }
 
-/**
- * Simple wrapper because EventEmitter has turned pure-JS as of node
- * 0.5.x.
- */
-exports.Parser = function(encoding) {
-    this.parser = new expat.Parser(encoding);
+var Parser = function(encoding) {
+  var that = this;
+
+  this.parser = new expat.Parser(encoding);
+  this.parser.emit = function() {
+    that.emit.apply(that, arguments);
+  };
+
+  //stream API
+  this.writable = true;
+  this.readable = true;
+};
+util.inherits(Parser, Stream);
 
-    var that = this;
-    this.parser.emit = function() {
-	that.emit.apply(that, arguments);
-    };
+Parser.prototype.parse = function(buf, isFinal) {
+  this.emit('data', buf);
+  return this.parser.parse(buf, isFinal);
 };
-util.inherits(exports.Parser, EventEmitter);
 
-exports.Parser.prototype.parse = function(buf, isFinal) {
-    return this.parser.parse(buf, isFinal);
+Parser.prototype.setEncoding = function(encoding) {
+  return this.parser.setEncoding(encoding);
 };
 
-exports.Parser.prototype.setEncoding = function(encoding) {
-    return this.parser.setEncoding(encoding);
+Parser.prototype.getError = function() {
+  return this.parser.getError();
+};
+Parser.prototype.stop = function() {
+  return this.parser.stop();
+};
+Parser.prototype.pause = function() {
+  return this.stop();
+};
+Parser.prototype.resume = function() {
+  return this.parser.resume();
 };
 
-exports.Parser.prototype.getError = function() {
-    return this.parser.getError();
+Parser.prototype.destroy = function() {
+  this.parser.stop();
+  this.end();
 };
-exports.Parser.prototype.stop = function() {
-    return this.parser.stop();
+
+Parser.prototype.destroySoon = function() {
+  this.destroy();
 };
-exports.Parser.prototype.pause = function() {
-    return this.stop();
+
+Parser.prototype.write = Parser.prototype.parse;
+
+Parser.prototype.end = function() {
+  this.emit('close');
+  this.emit('end');
 };
-exports.Parser.prototype.resume = function() {
-    return this.parser.resume();
+
+
+//Exports
+
+exports.Parser = Parser;
+
+exports.createParser = function(cb) {
+  var parser = new Parser();
+  if(cb)  { parser.on('startElement', cb); }
+  return parser;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git



More information about the Pkg-javascript-commits mailing list