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?