Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush alias #74

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -160,6 +160,20 @@ function shouldCompress(req, res) {
This module adds a `res.flush()` method to force the partially-compressed
response to be flushed to the client.

### res.flushCompression

This is an alias for the `res.flush()` method that is added by this module.

This supports use such as:

```javascript
// Not going to write again for a while. If compression middleware is
// installed let's tell it to flush what we've got through to the client.
if (res.flushCompression) {
res.flushCompression();
}
```

## Examples

### express/connect
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -66,7 +66,7 @@ function compression (options) {
var _write = res.write

// flush
res.flush = function flush () {
res.flush = res.flushCompression = function flush() {
if (stream) {
stream.flush()
}
Expand Down
14 changes: 14 additions & 0 deletions test/compression.js
Expand Up @@ -579,6 +579,20 @@ describe('compression()', function () {
.expect(200, done)
})

it('should have a res.flushCompression() alias', function (done) {
var server = createServer(null, function (req, res) {
res.statusCode = res.flush === res.flushCompression
? 200
: 500
res.flushCompression()
res.end()
})

request(server)
.get('/')
.expect(200, done)
})

it('should flush the response', function (done) {
var chunks = 0
var resp
Expand Down