lib/usb/usb-process.js
function RemoteWritableStream(process, daemon, writeHeaderFunc, closeHeaderFunc) {
  // Inherit from Writable Streams
  stream.Writable.call(this);
  // The id of the process that this is a stream of
  this.process = process;
  // The daemon to write data to
  this.daemon = daemon;
  // The amount of credit allocated to the stream (backpressure)
  this.credit = 0;
  // An array of backpressure entries
  this.backPressure = new Array(0);
  // A flag indicating whether this stream has passed EOF
  this.closed = false;

  // The function to generate the header necessary for a write
  this.writeHeaderFunc = writeHeaderFunc;
  // The function to generate the header necessary to close the stream
  this.closeHeaderFunc = closeHeaderFunc;
  // When the drain event is called, continue draining back pressured packets
  this.on('drain', () => this._drainBackPressure());
  // When the stream has finished
  this.once('finish', () => {
    // If the parent process is not already closed
    if (!this.process.closed) {
      // Tell the remote daemon that we are done
      this.daemon.write(closeHeaderFunc(this.process.id));
    }
    // Mark the flag for this stream
    this.closed = true;
  });
}
function RemoteWritableStream(process, daemon, writeHeaderFunc, closeHeaderFunc) {
  // Inherit from Writable Streams
  stream.Writable.call(this);
  // The id of the process that this is a stream of
  this.process = process;
  // The daemon to write data to
  this.daemon = daemon;
  // The amount of credit allocated to the stream (backpressure)
  this.credit = 0;
  // An array of backpressure entries
  this.backPressure = new Array(0);
  // A flag indicating whether this stream has passed EOF
  this.closed = false;

  // The function to generate the header necessary for a write
  this.writeHeaderFunc = writeHeaderFunc;
  // The function to generate the header necessary to close the stream
  this.closeHeaderFunc = closeHeaderFunc;
  // When the drain event is called, continue draining back pressured packets
  this.on('drain', () => this._drainBackPressure());
  // When the stream has finished
  this.once('finish', () => {
    // If the parent process is not already closed
    if (!this.process.closed) {
      // Tell the remote daemon that we are done
      this.daemon.write(closeHeaderFunc(this.process.id));
    }
    // Mark the flag for this stream
    this.closed = true;
  });
}
A wrapper on the Node Writable Stream to encapsulate stdin & control stream functionality