Update 'README.md'
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
6d4d62e79c
commit
8a49e38285
1 changed files with 18 additions and 2 deletions
20
README.md
20
README.md
|
@ -126,9 +126,9 @@ flaska.get('/api/test', function(ctx) {
|
|||
})
|
||||
```
|
||||
|
||||
### File stream/pipe
|
||||
### pipe
|
||||
|
||||
In cases where the response body is a pipe object (detected from the existance of `.pipe` property), flaska will automatically pipe the file for you. In addition, if a file stream is used, it will read the extension of the file being streamed and automatically fill in the mime-type for you in the `Content-Type` header.
|
||||
In cases where the response body is a pipe object (detected from the existance of `.pipe` property), flaska will automatically pipe it for you. In addition, if a file stream is used, it will read the extension of the file being streamed and automatically fill in the mime-type for you in the `Content-Type` header.
|
||||
|
||||
```
|
||||
flaska.get('/test.png', function(ctx) {
|
||||
|
@ -138,6 +138,22 @@ flaska.get('/test.png', function(ctx) {
|
|||
|
||||
Flaska will automatically close the file stream for you so you don't have to worry about that.
|
||||
|
||||
### FileResponse
|
||||
|
||||
Alternatively, if you want proper file support, I recommend using FileResponse object:
|
||||
|
||||
```
|
||||
import { FileResponse } from '../flaska.mjs'
|
||||
|
||||
flaska.get('/test.txt', function(ctx) {
|
||||
return fs.stat('./test/test.txt').then(function(stat) {
|
||||
ctx.body = new FileResponse('./test/test.txt', stat)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
This performs a real file stream support, uses pipes and supports all the HTTP shenanigans when it comes to dealing with files, including sending proper etag header, supporting partial response and lots of other things. This is one of the few libraries that actually implements full HTTP partial and etag support in a proper way, almost all other have one or two quirks that don't follow the spec properly.
|
||||
|
||||
### String
|
||||
|
||||
In other instances, Flaska will `.toString()` the body and send it in response with the specified type or default to `text/plain` if unspecified.
|
||||
|
|
Loading…
Reference in a new issue