Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   metaEngine.getAsync( id ).then( function( meta ){
  2.     console.log( 'success!' )
  3.     res.set( 'Content-Type', meta.mimeType )
  4.     res.set( 'Content-Length', file.length )
  5.     return storageEngine.getAsync( id )
  6.   }, function(){
  7.     console.log( 'failure!' )
  8.     res.status( 404 )
  9.   } ).then( function( file ){
  10.     console.log( 'still running' )
  11.     if( file.pipe ){
  12.       file.pipe( res )
  13.       return
  14.     } else if( typeof file === 'string' || Buffer.isBuffer( file ) ){
  15.       res.send( file )
  16.     } else {
  17.       res.status( 500 )
  18.       throw new Error( 'Invalid file returned. Please return ReadableStream, string, or Buffer' )
  19.     }
  20.   }, function(){
  21.     res.status( 500 )
  22.   } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement