front-matter
front-matter copied to clipboard
Streaming Support
Would be cool if there were an method like this:
fs.createReadStream('file.html')
.pipe(frontMatter.stream(function(attributes, stream) {
console.log(attributes)
stream.pipe(fs.createWriteStream('withoutyml.html'))
})
This is a great idea, I don't think it would be that hard to implement either.
What do you think of having a normal stream signature and emitting the attributes, maybe something like:
var fm = require('front-matter')
var stream = fm.createStream()
stream.on('attributes', function(attributes) {
console.log(attributes)
})
fs.createReadStream('my-file.html')
.pipe(stream)
.pipe(fs.createWriteStream('withoutyml.html'))
Your API was my first idea, but I think often you want to use the attributes to change the stream flow. Like in this example:
var fm = require('front-matter')
var stream = fm.createStream()
fs.createReadStream('my-file.html')
.pipe(stream(function(attributes, stream) {
(attributes.markdown ? stream.pipe(markdown2html()) : stream)
.pipe(fs.createWriteStream('withoutyml.html'))
})
Alternatively maybe there could be a callback that you can pass a transform stream:
var stream = fm.createStream(function(attributes, cb) {
if(attributes.markdown) cb(null, markdown2html())
else cb()
})
fs.createReadStream('my-file.html')
.pipe(stream)
.pipe(fs.createWriteStream('withoutyml.html'))
But I feel like the first solution is easier. What do you think?