/usr/lib/nodejs/node-expat/lib/node-expat.js is in node-node-expat 2.3.15-4build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | 'use strict'
var util = require('util')
var expat = require('bindings')('node_expat')
var Stream = require('stream').Stream
var Parser = function (encoding) {
this.encoding = encoding
this._getNewParser()
this.parser.emit = this.emit.bind(this)
// Stream API
this.writable = true
this.readable = true
}
util.inherits(Parser, Stream)
Parser.prototype._getNewParser = function () {
this.parser = new expat.Parser(this.encoding)
}
Parser.prototype.parse = function (buf, isFinal) {
return this.parser.parse(buf, isFinal)
}
Parser.prototype.setEncoding = function (encoding) {
this.encoding = encoding
return this.parser.setEncoding(this.encoding)
}
Parser.prototype.setUnknownEncoding = function (map, convert) {
return this.parser.setUnknownEncoding(map, convert)
}
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()
}
Parser.prototype.destroy = function () {
this.parser.stop()
this.end()
}
Parser.prototype.destroySoon = function () {
this.destroy()
}
Parser.prototype.write = function (data) {
var error, result
try {
result = this.parse(data)
if (!result) {
error = this.getError()
}
} catch (e) {
error = e
}
if (error) {
this.emit('error', error)
this.emit('close')
}
return result
}
Parser.prototype.end = function (data) {
var error, result
try {
result = this.parse(data || '', true)
if (!result) {
error = this.getError()
}
} catch (e) {
error = e
}
if (!error) {
this.emit('end')
} else {
this.emit('error', error)
}
this.emit('close')
}
Parser.prototype.reset = function () {
return this.parser.reset()
}
Parser.prototype.getCurrentLineNumber = function () {
return this.parser.getCurrentLineNumber()
}
Parser.prototype.getCurrentColumnNumber = function () {
return this.parser.getCurrentColumnNumber()
}
Parser.prototype.getCurrentByteIndex = function () {
return this.parser.getCurrentByteIndex()
}
exports.Parser = Parser
exports.createParser = function (cb) {
var parser = new Parser()
if (cb) {
parser.on('startElement', cb)
}
return parser
}
|