I proposed this already as an issue on GitHub 
(https://github.com/joyent/node/issues/8415#issuecomment-56346468), but 
seems it's more a convention and standarization thing.

My idea is to add an optional .type attibute to Node.js streams so when 
piping them it can be checked the format and adapt automatically if 
possible or throw an error due to incompatible formats. This is inspired by 
GStreamer 
Capabilities 
<http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-caps-api.html>
 and TermKit data streams headers 
<https://github.com/unconed/TermKit/blob/master/Node-API.md#pipes>, and 
would allow to process the streams metadata on heterogeneous environments 
(like building pipelines dynamically) without needing to inspect them.

This would only require that developers of the Writable streams set a 
checker or adaptor function on the 'pipe' event, using the .type attribute 
of both strems (themselves and the one they are being connected). The 
format of the .type attribute would be a string or array of strings with 
its MIME type, and when undefined/null/empty array it means accept 
everything (no type specified), so it's backward compatible. For streams in 
object mode, the .type attribute will have the MIME type of the individual 
chunks on the data event when they are strings or buffer objects.

As you can see this is an easy one, but would need stream developers start 
using the .type attribute so this can be useful when combining different 
streams between them, so probably this would be included in the streams 
documentation as a recomendation.

Thoughs? Suggestions? Comments?

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b9a19e6f-cb68-47f9-88d5-d1573820a7cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to