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 Support #24

Open
finnp opened this issue Apr 9, 2015 · 2 comments
Open

Streaming Support #24

finnp opened this issue Apr 9, 2015 · 2 comments
Labels

Comments

@finnp
Copy link

finnp commented Apr 9, 2015

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'))
   })
@jxson
Copy link
Owner

jxson commented Apr 10, 2015

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'))

@finnp
Copy link
Author

finnp commented Apr 10, 2015

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?

@jxson jxson added the Feature label Oct 20, 2015
@jxson jxson mentioned this issue Feb 13, 2016
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants