Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming To Parser in Node - Example Request #74

Open
joshvito opened this issue Nov 16, 2015 · 1 comment
Open

Streaming To Parser in Node - Example Request #74

joshvito opened this issue Nov 16, 2015 · 1 comment

Comments

@joshvito
Copy link

Can you share an example of a working script using Streaming To Parser in Node?
Using your README text generates an error.

fs.createReadStream('./path_to_file.html').pipe(parser);

I get this error in console:

_stream_readable.js:476
  dest.on('unpipe', onunpipe);
       ^
TypeError: Object #<Parser> has no method 'on'
    at ReadStream.Readable.pipe (_stream_readable.js:476:8)
    at Object.<anonymous> (C:\dev\autorelease\script.js:54:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Here is my simple script:

// get a file stream reader 
var reader = fs.createReadStream(process.argv[2]);

// get a file stream writer pointing to the json file to write to
var writer = fs.createWriteStream(input_json);

var htmlparser = require("htmlparser");
//var rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< /  script><!--<!-- Waah! -- -->";
//var sys = require("sys");

var handler = new htmlparser.DefaultHandler(function (error, dom) {
    if (error)
        logger.log('error', 'handler error in parser', {error: error});
    else
        logger.log('info', '', {dom: JSON.stringify(dom)});
});
var parser = new htmlparser.Parser(handler);
//parser.parseComplete(reader);
//sys.puts(sys.inspect(handler.dom, false, null));

// pipe everything to do the conversion
reader.pipe(parser).pipe(writer);
@Schaeff
Copy link

Schaeff commented Aug 31, 2017

I have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants