File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed
Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @foxify/http " : minor
3+ ---
4+
5+ Add ` response.bin ` method
Original file line number Diff line number Diff line change @@ -409,6 +409,18 @@ class Response extends ServerResponse<Request> {
409409 return this . set ( "Content-Disposition" , contentDisposition ( filename ) ) ;
410410 }
411411
412+ /**
413+ * Send Buffer response
414+ * @param body
415+ * @example
416+ * res.send(Buffer.from("wahoo"));
417+ */
418+ public bin ( body : Buffer ) : this {
419+ if ( ! this . hasHeader ( "content-type" ) ) this . type ( "bin" ) ;
420+
421+ return this . #send( body ) ;
422+ }
423+
412424 /**
413425 * Clear cookie `name`.
414426 *
@@ -933,14 +945,12 @@ class Response extends ServerResponse<Request> {
933945 public send ( body ?: Buffer | JsonT | string ) : this {
934946 if ( typeof body === "string" ) return this . text ( body ) ;
935947
936- if ( Buffer . isBuffer ( body ) ) {
937- if ( ! this . hasHeader ( "content-type" ) ) this . type ( "bin" ) ;
938- } else if ( body === null ) {
939- return this . #send( "" ) ;
940- // eslint-disable-next-line no-undefined
941- } else if ( body !== undefined ) {
942- return this . json ( body ) ;
943- }
948+ if ( Buffer . isBuffer ( body ) ) return this . bin ( body ) ;
949+
950+ if ( body === null ) return this . #send( "" ) ;
951+
952+ // eslint-disable-next-line no-undefined
953+ if ( body !== undefined ) return this . json ( body ) ;
944954
945955 return this . #send( body ) ;
946956 }
You can’t perform that action at this time.
0 commit comments