From 6a65d6f2e701e5a750f38769b19242fb537643b8 Mon Sep 17 00:00:00 2001 From: marty Date: Fri, 8 May 2015 10:29:45 -0700 Subject: [PATCH] stream file on http serve --- src/nodes/serve/serveFile.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/nodes/serve/serveFile.js b/src/nodes/serve/serveFile.js index b26279c..dc27c26 100644 --- a/src/nodes/serve/serveFile.js +++ b/src/nodes/serve/serveFile.js @@ -1,13 +1,11 @@ import { lookup } from 'mime'; -import { readFile } from 'sander'; +import { Promise, createReadStream } from 'sander'; export default function serveFile ( filepath, request, response ) { - return readFile( filepath ).then( data => { - response.statusCode = 200; - response.setHeader( 'Content-Type', lookup( filepath ) ); - response.setHeader( 'Content-Length', data.length ); - response.write( data ); - response.end(); - }); + response.statusCode = 200; + response.setHeader( 'Content-Type', lookup( filepath ) ); + createReadStream( filepath ).pipe( response ); + + return Promise.resolve(); }