@@ -88,6 +88,7 @@ const {
88
88
validateObject,
89
89
} = require ( 'internal/validators' ) ;
90
90
const Buffer = require ( 'buffer' ) . Buffer ;
91
+ const { pipeline } = require ( 'stream' ) ;
91
92
const { setInterval, clearInterval } = require ( 'timers' ) ;
92
93
let debug = require ( 'internal/util/debuglog' ) . debuglog ( 'http' , ( fn ) => {
93
94
debug = fn ;
@@ -225,6 +226,30 @@ function ServerResponse(req) {
225
226
ObjectSetPrototypeOf ( ServerResponse . prototype , OutgoingMessage . prototype ) ;
226
227
ObjectSetPrototypeOf ( ServerResponse , OutgoingMessage ) ;
227
228
229
+ ServerResponse . prototype . sendFile = function ( file , options , callback ) {
230
+ if ( typeof options === 'function' ) {
231
+ callback = options ;
232
+ options = null ;
233
+ }
234
+
235
+ validateObject ( options , 'options' , { nullable : true } ) ;
236
+ validateCallback ( callback , 'callback' ) ;
237
+
238
+ const { start, end, highWaterMark } = options ?? { } ;
239
+
240
+ let path
241
+ let fd
242
+
243
+ if ( file instanceof FileHandle || Number . isInteger ( file ) ) {
244
+ fd = file
245
+ } else {
246
+ path = file
247
+ }
248
+
249
+ // TODO (perf): Optimize this...
250
+ pipeline ( fs . createReadStream ( path , { fd, start, end, highWaterMark } ) , callback ) ;
251
+ } ;
252
+
228
253
ServerResponse . prototype . _finish = function _finish ( ) {
229
254
if ( this [ kServerResponseStatistics ] && hasObserver ( 'http' ) ) {
230
255
stopPerf ( this , kServerResponseStatistics , {
0 commit comments