Optional MIME type for streams

26 views
Skip to first unread message

Jesús Leganés Combarro

unread,
Sep 22, 2014, 8:37:57 AM9/22/14
to nod...@googlegroups.com
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 and TermKit data streams headers, 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?

Aria Stewart

unread,
Sep 22, 2014, 11:02:55 AM9/22/14
to nod...@googlegroups.com


On Monday, September 22, 2014 8:37:57 AM UTC-4, Jesús Leganés Combarro wrote:
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 and TermKit data streams headers, 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.


Interesting idea!

I'm not sure it fits at the same level as streams -- it's a much higher level concept, since streams don't represent files, always -- they're anything from TCP sockets to a lazy map-reduce chain, too.

It'd be interesting to see a few tools for checking things and see how it'd get used. If it's purely advisory, it can probably live outside the core distro entirely. 

Aria
Reply all
Reply to author
Forward
0 new messages