lib/impl/pdfGeneration/cacheFiles.js
function cacheSubmissionFile(params, fileToStreamTo, cb) {
  //If the files are remote, use the mbaas client
  logger.debug("cacheFiles: cacheSubmissionFile submission", {params: params, fileToStreamTo: fileToStreamTo});
  if (params.options.filesAreRemote) {
    return downloadFileFromMbaas(params, fileToStreamTo, cb);
  }

  //File is in the local database, load it there
  getSubmissionFile(params.connections, params.options, {
    _id: params.fileId
  }, function(err, fileDetails) {
    if (err) {
      logger.error("cacheFiles: cacheSubmissionFile getSubmissionFile", {error: err});
      return cb(err);
    }

    fileDetails.stream.on('error', function(err) {
      logger.error("cacheFiles: cacheSubmissionFile Error Streaming File With Id: " + params.fileId);
      return cb(err);
    });

    fileDetails.stream.on('end', function() {
      logger.debug("cacheFiles: cacheSubmissionFile Stream Complete For File With Id: " + params.fileId);
      return cb(undefined, fileDetails);
    });

    //Streaming The File
    fileDetails.stream.pipe(fileToStreamTo);
    fileDetails.stream.resume();
  });
}
function cacheSubmissionFile(params, fileToStreamTo, cb) {
  //If the files are remote, use the mbaas client
  logger.debug("cacheFiles: cacheSubmissionFile submission", {params: params, fileToStreamTo: fileToStreamTo});
  if (params.options.filesAreRemote) {
    return downloadFileFromMbaas(params, fileToStreamTo, cb);
  }

  //File is in the local database, load it there
  getSubmissionFile(params.connections, params.options, {
    _id: params.fileId
  }, function(err, fileDetails) {
    if (err) {
      logger.error("cacheFiles: cacheSubmissionFile getSubmissionFile", {error: err});
      return cb(err);
    }

    fileDetails.stream.on('error', function(err) {
      logger.error("cacheFiles: cacheSubmissionFile Error Streaming File With Id: " + params.fileId);
      return cb(err);
    });

    fileDetails.stream.on('end', function() {
      logger.debug("cacheFiles: cacheSubmissionFile Stream Complete For File With Id: " + params.fileId);
      return cb(undefined, fileDetails);
    });

    //Streaming The File
    fileDetails.stream.pipe(fileToStreamTo);
    fileDetails.stream.resume();
  });
}
function cacheSubmissionFile ( params , fileToStreamTo , cb ) { //If the files are remote, use the mbaas client logger . debug ( "cacheFiles: cacheSubmissionFile submission" , { params : params , fileToStreamTo : fileToStreamTo } ) ; if ( params . options . filesAreRemote ) { return downloadFileFromMbaas ( params , fileToStreamTo , cb ) ; } //File is in the local database, load it there getSubmissionFile ( params . connections , params . options , { _id : params . fileId } , function ( err , fileDetails ) { if ( err ) { logger . error ( "cacheFiles: cacheSubmissionFile getSubmissionFile" , { error : err } ) ; return cb ( err ) ; } fileDetails . stream . on ( 'error' , function ( err ) { logger . error ( "cacheFiles: cacheSubmissionFile Error Streaming File With Id: " + params . fileId ) ; return cb ( err ) ; } ) ; fileDetails . stream . on ( 'end' , function ( ) { logger . debug ( "cacheFiles: cacheSubmissionFile Stream Complete For File With Id: " + params . fileId ) ; return cb ( undefined , fileDetails ) ; } ) ; //Streaming The File fileDetails . stream . pipe ( fileToStreamTo ) ; fileDetails . stream . resume ( ) ; } ) ; }
Streaming The File From The Database.

@param params
- options
- fileId
- connections
@param fileToStreamTo
@param cb
Streaming The File From The Database .