Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Send binary data via ChildProcess.send #5727

Closed
@EugenDueck

Description

@EugenDueck

Is there a way to send binary data efficiently to a child process using (something as easy to use as) ChildProcess.send? send(buf) does not work as expected:

var cluster = require('cluster');

if (cluster.isWorker)
{
  process.on('message', function messageHandler(msg)
  {
    console.log("msg: " + JSON.stringify(msg) +
        " - type: " + typeof msg +
        " - buf? " + Buffer.isBuffer(msg));
  });
}
else
{
  var buffer = new Buffer(2);
  buffer[0] = 5;
  buffer[1] = 88; 
  var worker = cluster.fork();
  worker.on("online", function() { worker.send(buffer); });
}

The above will log

msg: [5,88] - type: object - buf? false

msg turns out to be a JSONified version of the original buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions