Permalink
Browse files

Testing out buffers and multibyte stuff. Doesn't work

  • Loading branch information...
1 parent 463dcae commit 7ac096c882e67a22c17ab1377e0c16a66d09858f @isaacs isaacs committed Oct 24, 2011
Showing with 19 additions and 13 deletions.
  1. +3 −3 examples/not-pretty.xml
  2. +1 −1 examples/pretty-print.js
  3. +15 −9 lib/sax.js
View
6 examples/not-pretty.xml
@@ -1,8 +1,8 @@
<root>
- something<else> blerm <slurm
-
+ΩΩΩΩΩΩΩΩ something<else> blerm <slurm
+omegas="ΩΩΩΩΩΩΩΩ"
attrib =
- "blorg" ></else><!-- COMMENT!
+ "blorg" ><ΩΩΩΩΩΩΩΩ utf=true /></else><!-- COMMENT!
--><![CDATA[processing...]]> <selfclosing tag="blr>&quot;"/> a bit down here</root>
View
2 examples/pretty-print.js
@@ -59,7 +59,7 @@ if (!process.argv[2]) {
"TODO: read from stdin or take a file")
}
var xmlfile = require("path").join(process.cwd(), process.argv[2])
-var fstr = fs.createReadStream(xmlfile, { encoding: "utf8" })
+var fstr = fs.createReadStream(xmlfile)//, { encoding: "utf8" })
function print (c) {
if (!process.stdout.write(c)) {
View
24 lib/sax.js
@@ -135,13 +135,6 @@ SAXParser.prototype = {
close : function () { return this.write(null) },
}
-try {
- var Stream = require("stream").Stream
-} catch (ex) {
- var Stream = function () {}
-}
-
-
var streamWraps = sax.EVENTS.filter(function (ev) {
return ev !== "error" && ev !== "end"
})
@@ -150,11 +143,22 @@ function createStream (strict, opt) {
return new SAXStream(strict, opt)
}
+try {
+ var Stream = require("stream").Stream
+ var StringDecoder = require("string_decoder").StringDecoder
+} catch (ex) {
+ var Stream = null
+ var StringDecoder = null
+}
+
function SAXStream (strict, opt) {
+ if (!Stream) throw new Error("Stream base classes not implemented")
+
if (!(this instanceof SAXStream)) return new SAXStream(strict, opt)
Stream.apply(me)
+ this._decoder = new StringDecoder("utf8")
this._parser = new SAXParser(strict, opt)
this.writable = true
this.readable = true
@@ -194,7 +198,8 @@ SAXStream.prototype = Object.create(Stream.prototype,
{ constructor: { value: SAXStream } })
SAXStream.prototype.write = function (data) {
- this._parser.write(data.toString())
+ // this._parser.write(data.toString())
+ this._parser.write(data)
this.emit("data", data)
return true
}
@@ -556,6 +561,7 @@ function parseEntity (parser) {
}
function write (chunk) {
+ console.error(Buffer.isBuffer(chunk))
var parser = this
if (this.error) throw this.error
if (parser.closed) return error(parser,
@@ -594,7 +600,7 @@ function write (chunk) {
} else parser.column ++
}
}
- parser.textNode += chunk.substring(starti, i-1)
+ parser.textNode += chunk.slice(starti, i-1)
}
if (c === "<") parser.state = S.OPEN_WAKA
else {

0 comments on commit 7ac096c

Please sign in to comment.