src/transport-multipart-interceptor.js
function unpackToMessage(request, forwardFunction) {
  const busboy = new Busboy({
    headers: request.headers
  });

  return new Promise((resolve, reject) => {
    // the message which will be forwarded
    const newMessage = {};

    let resultPromise;

    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
      if (fieldname === 'payload') {
        // This is a stream payload
        newMessage.payload = file;
        if (forwardFunction) {
          resolve(forwardFunction(newMessage));
        } else {
          resolve(newMessage);
        }
      }
    });

    busboy.on('field', function(
      fieldname,
      val,
      fieldnameTruncated,
      valTruncated
    ) {
      if (
        fieldname === 'info' ||
        fieldname === 'hops' ||
        fieldname === 'payload'
      ) {
        newMessage[fieldname] = JSON.parse(val);
      }
    });

    request.pipe(busboy);
  });
}
function unpackToMessage(request, forwardFunction) {
  const busboy = new Busboy({
    headers: request.headers
  });

  return new Promise((resolve, reject) => {
    // the message which will be forwarded
    const newMessage = {};

    let resultPromise;

    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
      if (fieldname === 'payload') {
        // This is a stream payload
        newMessage.payload = file;
        if (forwardFunction) {
          resolve(forwardFunction(newMessage));
        } else {
          resolve(newMessage);
        }
      }
    });

    busboy.on('field', function(
      fieldname,
      val,
      fieldnameTruncated,
      valTruncated
    ) {
      if (
        fieldname === 'info' ||
        fieldname === 'hops' ||
        fieldname === 'payload'
      ) {
        newMessage[fieldname] = JSON.parse(val);
      }
    });

    request.pipe(busboy);
  });
}
function unpackToMessage ( request , forwardFunction ) { const busboy = new Busboy ( { headers : request . headers } ) ; return new Promise ( ( resolve , reject ) => { // the message which will be forwarded const newMessage = { } ; let resultPromise ; busboy . on ( 'file' , function ( fieldname , file , filename , encoding , mimetype ) { if ( fieldname === 'payload' ) { // This is a stream payload newMessage . payload = file ; if ( forwardFunction ) { resolve ( forwardFunction ( newMessage ) ) ; } else { resolve ( newMessage ) ; } } } ) ; busboy . on ( 'field' , function ( fieldname , val , fieldnameTruncated , valTruncated ) { if ( fieldname === 'info' || fieldname === 'hops' || fieldname === 'payload' ) { newMessage [ fieldname ] = JSON . parse ( val ) ; } } ) ; request . pipe ( busboy ) ; } ) ; }
Unpacks a message from a multipart http request

@param request The incomming http request
@param forwardFunction The function to call with the new generated message.
The function must return a Promise. If no 'forwardFunction' is given
It will return the message in the promise

@return Promise A promise with the result of the forwardFunction
Unpacks a message from a multipart http request