src/process-streams.js
function wrapProcess (tmpIn, tmpOut, processProvider) {
  return createStream(tmpIn, tmpOut, function (input, output, callback) {
    var _this = this
    var process = processProvider.call(this, tmpIn, tmpOut)
    process.on('error', function (error) {
      callback(error)
    })
    if (!tmpIn) {
      input.pipe(process.stdin).on('error', function (error) {
        if (error.code === 'ECONNRESET' && error.syscall === 'read') {
          // This can happen if the process closes stdin before all data has been read
          // e.g. in ps.spawn("exiftool", ["-s3", "-MimeType", "-fast","-"]);
          // This is not necessarily an error, since the output is still valid
          _this.emit('input-closed', error)
        } else if (error.code === 'EPIPE' && error.syscall === 'write') {
          // This also can happen if the process closes stdin before all data has been read
          // e.g. in ps.spawn("head", ["-2"]);
          // This is not necessarily an error, since the output is still valid
          _this.emit('input-closed', error)
        } else {
          // This "emit" causes test cases to fail
          // it is most likely a followup-error of an error that is already
          // emitted
          // _this.emit("error", error);
        }
      })
    }
    if (!tmpOut) {
      process.stdout.pipe(output)
    }
    process.on('exit', function (code, signal) {
      _this.emit('exit', code, signal)
      callback(null)
    })
  })
}
function wrapProcess (tmpIn, tmpOut, processProvider) {
  return createStream(tmpIn, tmpOut, function (input, output, callback) {
    var _this = this
    var process = processProvider.call(this, tmpIn, tmpOut)
    process.on('error', function (error) {
      callback(error)
    })
    if (!tmpIn) {
      input.pipe(process.stdin).on('error', function (error) {
        if (error.code === 'ECONNRESET' && error.syscall === 'read') {
          // This can happen if the process closes stdin before all data has been read
          // e.g. in ps.spawn("exiftool", ["-s3", "-MimeType", "-fast","-"]);
          // This is not necessarily an error, since the output is still valid
          _this.emit('input-closed', error)
        } else if (error.code === 'EPIPE' && error.syscall === 'write') {
          // This also can happen if the process closes stdin before all data has been read
          // e.g. in ps.spawn("head", ["-2"]);
          // This is not necessarily an error, since the output is still valid
          _this.emit('input-closed', error)
        } else {
          // This "emit" causes test cases to fail
          // it is most likely a followup-error of an error that is already
          // emitted
          // _this.emit("error", error);
        }
      })
    }
    if (!tmpOut) {
      process.stdout.pipe(output)
    }
    process.on('exit', function (code, signal) {
      _this.emit('exit', code, signal)
      callback(null)
    })
  })
}
function wrapProcess ( tmpIn , tmpOut , processProvider ) { return createStream ( tmpIn , tmpOut , function ( input , output , callback ) { var _this = this var process = processProvider . call ( this , tmpIn , tmpOut ) process . on ( 'error' , function ( error ) { callback ( error ) } ) if ( ! tmpIn ) { input . pipe ( process . stdin ) . on ( 'error' , function ( error ) { if ( error . code === 'ECONNRESET' && error . syscall === 'read' ) { // This can happen if the process closes stdin before all data has been read // e.g. in ps.spawn("exiftool", ["-s3", "-MimeType", "-fast","-"]); // This is not necessarily an error, since the output is still valid _this . emit ( 'input-closed' , error ) } else if ( error . code === 'EPIPE' && error . syscall === 'write' ) { // This also can happen if the process closes stdin before all data has been read // e.g. in ps.spawn("head", ["-2"]); // This is not necessarily an error, since the output is still valid _this . emit ( 'input-closed' , error ) } else { // This "emit" causes test cases to fail // it is most likely a followup-error of an error that is already // emitted // _this.emit("error", error); } } ) } if ( ! tmpOut ) { process . stdout . pipe ( output ) } process . on ( 'exit' , function ( code , signal ) { _this . emit ( 'exit' , code , signal ) callback ( null ) } ) } ) }
Wraps a process provided by a function in a stream such that the stream input is piped to stdin and stdout is piped to the stream output.
If tmpIn is provided, no pipe is set up to stdin. Instead, the data is piped into tmpIn which can than be provided to the process
as command line argument. The same applies for stdout.
@param processProvider
@param tmpIn the location of a temporary file that is filled with the input data.
@param tmpOut the location of a temporary file that the process writes to and that is used as source to the stream output.
Wraps a process provided by a function in a stream such that the stream input is piped to stdin and stdout is piped to the stream output . If tmpIn is provided no pipe is set up to stdin . Instead the data is piped into tmpIn which can than be provided to the process as command line argument . The same applies for stdout .