Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reading from streams seems to work

  • Loading branch information...
commit 3fdad3307854fbcee304f024cea3aebb757d9031 1 parent 84d9e02
@Floby authored
View
4 lib/BufferStream.js
@@ -10,6 +10,7 @@ function BufferStream () {
sys.inherits(BufferStream, Stream);
BufferStream.prototype.end = function end(str) {
+ if(str) this.write(str);
this.finished = true;
this.emit('update');
};
@@ -29,5 +30,8 @@ BufferStream.prototype.flush = function flush() {
BufferStream.prototype.isEmpty = function isEmpty() {
return this._buffered.length == 0;
};
+BufferStream.prototype.destroy = function destroy() {
+ this.end();
+};
module.exports = BufferStream;
View
15 lib/template.js
@@ -29,6 +29,7 @@ Template.prototype.data = function(data) {
*/
function make_print(tpl) {
return function(str) {
+ if(str instanceof Stream) return tpl.addStream(str);
if(tpl._buffers.length) {
//bufferize data
// get the last buffer in the list
@@ -89,6 +90,18 @@ function make_include(tpl) {
}
}
+Template.prototype.addStream = function addStream(stream) {
+ var self = this
+ var buffer = new BufferStream;
+ buffer.on('update', function() {
+ self._newData();
+ });
+ stream.pipe(buffer);
+ stream.resume();
+ this._buffers.push(buffer);
+};
+
+
Template.prototype.run = function run() {
var self = this;
this._directory = path.dirname(this.filename);
@@ -134,6 +147,7 @@ Template.prototype.run = function run() {
});
};
Template.prototype._newData = function _newData(logme) {
+ //console.log(this._buffers);
// flush all finished buffers
while(this._buffers[0] && this._buffers[0].finished) {
this._write(this._buffers[0].getData());
@@ -155,7 +169,6 @@ Template.prototype._newData = function _newData(logme) {
};
Template.prototype._write = function _write(data) {
- //console.log('printing data %s', JSON.stringify(data));
this.emit('data', data);
};
View
1  test/echo-file.js
@@ -2,6 +2,7 @@ var blue = require('../');
var Template = blue.Template;
var fs = require('fs');
var stream = fs.createReadStream(__filename, {encoding:'utf8'});
+stream.pause();
var t = new Template(__dirname+'/echo-file.tpl');
t.data({stream:stream})
t.pipe(process.stdout);
View
2  test/echo-file.tpl
@@ -1 +1,3 @@
+<pre>
<% print(data.stream); %>
+</pre>
Please sign in to comment.
Something went wrong with that request. Please try again.