Open itsjohncs opened 9 years ago
I could also just make a separate decorator for binary pipelines. It does seem to be a fairly different use case because most of the pipes I've made so far operate line-by-line, whereas binary pipes would want to deal with arbitrary chunks...
The second seems better to me, going to try it.
Hmm, I seem to have forgotten why the current implementation is bad... Maybe it will come to me with time.
I think the current implementation is bad because the files are automatically opened for you. The binary pipelines are necessary in the first place because we do some trickiness to ensure that various ways to encode unicode are picked up properly, and we don't want that trickiness to apply if the files aren't textual.
I think an interesting alternative would be lazily opening the files. So initially your pipeline function is given a list of special file objects that haven't been opened yet (so are just filenames). You can explicitly open them yourself (and pass in whatever parameters you want to enable/disable the unicode decoding), or you can let them be opened by the pipes (or whatever those are called) which will open them if they're not already open.
This should give you sane behavior most of the time, but it does feel a little magical. I think explicitly saying what parameters specific pipes will use when opening the pipeline (aside: holy crap I need to sit down and define this vocab better) will solve the magical problem tidily.
My homework: read and appreciate the Node.js Stream API.
Learned thing number 1: stream is a good name for the thing that the pipeline function receives.
Well I guess currently stream would be a bad name, because the thing is not a stream. It's more like a list that each pipe can mutate. It probably should be a stream though, because those are pretty understandable and will align well with Gulp.
I can also pretty much implement Vinyl. There's not much there to implement, and it seems to work well.
An idea I had is that Phial won't take care of trying to open the file, and will instead just package up all of the paths into special path objects (or just leave them as strings...) and then you can pipe the names into something that will open the files.
return paths | phial.pipes.open_all
. I'm not sure how this idea could be extended to customize how the output file(s) is/are opened.