Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

now fully supporting streaming

  • Loading branch information...
commit 1f73664950deda1d3672c0813502230f5cecaaba 1 parent 0d0f774
Pedro Teixeira authored
13 index.js
@@ -77,15 +77,14 @@ module.exports = function (opts) {
77 77 parser.write(buf.toString());
78 78 };
79 79
80   - stream.end = function (buf) {
  80 + stream.end = function (buf, next) {
81 81 if (buf !== undefined) stream.write(buf);
82 82
83 83 if (pos < parser.position) {
84 84 var s = buffered.slice(0, parser.position - pos);
85   - stream.raw(s, function() {
86   - stream.emit('end');
87   - });
88   - } else { stream.emit('end'); }
  85 + stream.raw(s);
  86 + }
  87 + parser.close();
89 88
90 89 };
91 90
@@ -96,6 +95,10 @@ module.exports = function (opts) {
96 95 });
97 96 };
98 97
  98 + parser.onend = function() {
  99 + stream.emit('end');
  100 + };
  101 +
99 102 //
100 103 // Pausing and resuming
101 104 //
2  lib/select.js
@@ -139,7 +139,7 @@ module.exports = function (parser, opts) {
139 139 });
140 140 }, function() {
141 141 if (!updating) stream.emit('data', s);
142   - done();
  142 + if (done) { done(); }
143 143 });
144 144 };
145 145
2  test/update.html
@@ -27,4 +27,4 @@
27 27 </div>
28 28 <div class="g">EVERYTHING IS TERRIBLE</div>
29 29 </body>
30   -</html>
  30 +</html>
62 test/update_streaming.js
... ... @@ -0,0 +1,62 @@
  1 +var test = require('tap').test;
  2 +var trumpet = require('../');
  3 +var fs = require('fs');
  4 +var BufferedStream = require('bufferedstream');
  5 +
  6 +test('update', function (t) {
  7 + t.plan(2);
  8 + var html = fs.readFileSync(__dirname + '/update_target.html', 'utf8');
  9 +
  10 + var tr = trumpet();
  11 + fs.createReadStream(__dirname + '/update.html').pipe(tr);
  12 +
  13 + var spans = [ 'tacos', 'y', 'burritos' ];
  14 +
  15 + tr.select('.b span', function (node) {
  16 + node.update(function (html) {
  17 + var stream = new BufferedStream();
  18 + stream.end(html.toUpperCase());
  19 + return stream;
  20 + });
  21 + });
  22 +
  23 + tr.select('.c', function (node) {
  24 + node.update(function() {
  25 + var stream = new BufferedStream();
  26 + stream.end('---');
  27 + return stream;
  28 + });
  29 + });
  30 +
  31 + tr.select('.d', function (node) {
  32 + node.remove();
  33 + });
  34 +
  35 + tr.select('.e', function (node) {
  36 + node.remove();
  37 + });
  38 +
  39 + tr.select('.f', function (node) {
  40 + node.replace(function() {
  41 + var stream = new BufferedStream();
  42 + stream.end('<b>NOTHING TO SEE HERE</b>');
  43 + return stream;
  44 + });
  45 + });
  46 +
  47 + tr.select('.g', function (node) {
  48 + node.replace(function (html) {
  49 + t.equal(html, '<div class="g">EVERYTHING IS TERRIBLE</div>');
  50 + var stream = new BufferedStream();
  51 + stream.end('<blink>TERRIBLE</blink>');
  52 + return stream;
  53 + });
  54 + });
  55 +
  56 + var data = '';
  57 + tr.on('data', function (buf) { data += buf });
  58 +
  59 + tr.on('end', function () {
  60 + t.equal(data, html);
  61 + });
  62 +});
2  test/update_target.html
@@ -18,4 +18,4 @@
18 18 <b>NOTHING TO SEE HERE</b>
19 19 <blink>TERRIBLE</blink>
20 20 </body>
21   -</html>
  21 +</html>

0 comments on commit 1f73664

Please sign in to comment.
Something went wrong with that request. Please try again.