Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass more advanced objects between processes #19

Closed
notslang opened this issue Aug 20, 2014 · 6 comments
Closed

pass more advanced objects between processes #19

notslang opened this issue Aug 20, 2014 · 6 comments

Comments

@notslang
Copy link
Collaborator

The HTML5 web-workers spec specifies a way to pass dates, regexps, buffers, and other advanced datatypes between processes. There's an implementation of that here: https://www.npmjs.org/package/structured-clone

We could also use JASON, but that's a bit more complicated, and isn't a part of a W3C standard.

@rvagg
Copy link
Owner

rvagg commented Aug 21, 2014

Protocol Buffers might be the way to go with this, fast and efficient: https://github.com/mafintosh/protocol-buffers

@notslang
Copy link
Collaborator Author

oh wow... faster than native JSON sterilization? that's pretty insane... definitely worth looking into

@kwiatkk1
Copy link

But a drawback of Protocol Buffers is that it requires a schema to work. I think that the BSON from mongodb looks like a better option to use in this particular case as it's schema-less.

@guybedford
Copy link

I've been wanting to integrate cbor for data passing here using https://www.npmjs.com/package/cbor (http://hildjj.github.io/node-cbor/), but it seems like passing buffers isn't supported. Perhaps this project could natively use cbor with possible streaming for transport if it turns out faster than JSON encode / decode for bandwidth savings or streaming possibilities? Could be worth some experimenting...

@rvagg
Copy link
Owner

rvagg commented May 3, 2019

if #90 gets merged and we get worker thread support then native structured clone will be a thing, considering this stale for now.

@rvagg rvagg closed this as completed May 3, 2019
@JakeHamix
Copy link

JakeHamix commented Jul 1, 2019

I've been wanting to integrate cbor for data passing here using https://www.npmjs.com/package/cbor (http://hildjj.github.io/node-cbor/), but it seems like passing buffers isn't supported. Perhaps this project could natively use cbor with possible streaming for transport if it turns out faster than JSON encode / decode for bandwidth savings or streaming possibilities? Could be worth some experimenting...

@guybedford Actually, it seems that you can pass the buffers just alright right away, no need to implement cbor here - not sure about the other advanced objects. I've just deployed this package as a part of our mailing system, where I pass mail attachments to nodemailer as buffers. Sure, they got malformed a little bit on the way, but parsing it again did the trick.

const nodeMailer = require('nodemailer');

module.exports.sendMail = (mailOptions, transporterOptions, callback) => {

    mailOptions.attachments = mailOptions.attachments.map(item => {
        item.content = Buffer.from(item.content.data);
        return item;
    });

    const transporter = nodeMailer.createTransport(transporterOptions);
    return transporter.sendMail(mailOptions, (error, info) => {
        callback(error || null, info);
    });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants