I am working on a test system/framework using nodejs where I need to send binary data as strings in some circumstances.
One part of the system is a webserver/reverse proxy that will either serve a static file or forward the request to an external server unless the request will be intercepted and processed by a remote hook. (Trying to simplify as much irrelevant information here ;), anyway the various parts of the system are either running as node instances and some may be running JS in rhino or in embedded webbrowsers. Anyway, I has chosen faye as the messaging framework to pass data between these subsystems so that means that data has to be representable as JS objects and be serializable as JSON strings. Now the web remote-hook works so that it registers itself in the main webserver over faye so that all requests matching the registred patterns will be forwarded to this remote-hook in a faye/bayeux message. Now the remote-hook will get inbound faye messages for these requests and the remote-hook will fetch them using HTTP or mock/stub them or manipulate them in any way before sending back the response over faye. The problem is when sending the entityBody back to the webserver process it can be binary such as images etc. By default node converts binary data chunks to utf8 and that fails. Base64 works but adds an overhead and also makes it harder to work with plain text data such as text/html or application/json, so i chosed "binary" as the documentation says is a valid string conversion except for this remark in: http://nodejs.org/api/buffer.html#buffer_class_buffer 'binary' - A way of encoding raw binary data into strings by using only the first 8 bits of each character. This encoding method is deprecated and should be avoided in favor of Buffer objects where possible. *This encoding will be removed in future versions of Node.* * * Its the last statement I didnt like, I have not successfully converted binary data to utf8 and back to binary so far, but "binary" obviously works as do "base64", will "binary" be removed or is it the documentation that tries to prevent "stupid" hacks. Binary data in JS strings has been used from time to time so its not new, but its of course browser hack since nowdays typed arrays are the way to go. But when serialising over the wire its nice to at least be able to crunch binary data as unicode. * * //Mattias Ernelli -- Job Board: http://jobs.nodejs.org/ Posting guidelines: 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
