{"action":"created","issue":{"url":"https://api.github.com/repos/expressjs/compression/issues/80","repository_url":"https://api.github.com/repos/expressjs/compression","labels_url":"https://api.github.com/repos/expressjs/compression/issues/80/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/compression/issues/80/comments","events_url":"https://api.github.com/repos/expressjs/compression/issues/80/events","html_url":"https://github.com/expressjs/compression/pull/80","id":153628274,"number":80,"title":"Adding callback to res.write and res.end for streaming support","user":{"login":"jpodwys","id":5660076,"avatar_url":"https://avatars.githubusercontent.com/u/5660076?v=3","gravatar_id":"","url":"https://api.github.com/users/jpodwys","html_url":"https://github.com/jpodwys","followers_url":"https://api.github.com/users/jpodwys/followers","following_url":"https://api.github.com/users/jpodwys/following{/other_user}","gists_url":"https://api.github.com/users/jpodwys/gists{/gist_id}","starred_url":"https://api.github.com/users/jpodwys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpodwys/subscriptions","organizations_url":"https://api.github.com/users/jpodwys/orgs","repos_url":"https://api.github.com/users/jpodwys/repos","events_url":"https://api.github.com/users/jpodwys/events{/privacy}","received_events_url":"https://api.github.com/users/jpodwys/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/expressjs/compression/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/expressjs/compression/labels/needs%20tests","name":"needs tests","color":"e11d21"},{"url":"https://api.github.com/repos/expressjs/compression/labels/pr","name":"pr","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"dougwilson","id":67512,"avatar_url":"https://avatars.githubusercontent.com/u/67512?v=3","gravatar_id":"","url":"https://api.github.com/users/dougwilson","html_url":"https://github.com/dougwilson","followers_url":"https://api.github.com/users/dougwilson/followers","following_url":"https://api.github.com/users/dougwilson/following{/other_user}","gists_url":"https://api.github.com/users/dougwilson/gists{/gist_id}","starred_url":"https://api.github.com/users/dougwilson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dougwilson/subscriptions","organizations_url":"https://api.github.com/users/dougwilson/orgs","repos_url":"https://api.github.com/users/dougwilson/repos","events_url":"https://api.github.com/users/dougwilson/events{/privacy}","received_events_url":"https://api.github.com/users/dougwilson/received_events","type":"User","site_admin":false},"milestone":null,"comments":26,"created_at":"2016-05-08T01:07:15Z","updated_at":"2016-05-24T06:30:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/expressjs/compression/pulls/80","html_url":"https://github.com/expressjs/compression/pull/80","diff_url":"https://github.com/expressjs/compression/pull/80.diff","patch_url":"https://github.com/expressjs/compression/pull/80.patch"},"body":"I want to be able to use `compression` to enable GZIP on streamed responses that flush multiple chunks to the browser whenever the implementer wants. (This is especially useful when implementing a [BigPipe](https://www.facebook.com/notes/facebook-engineering/bigpipe-pipelining-web-pages-for-high-performance/389414033919/) algorithm such as with my [`express-stream`](https://github.com/jpodwys/express-stream) library.) As a result, I need a sure way of flushing only after a chunk of output has been zipped.\r\n\r\nCurrently, the following code encounters a race condition because `res.write` is not blocking. As a result, it's possible that `res.flush` will execute before `res.write` completes.\r\n\r\n```javascript\r\nres.write(html);\r\nif(res.flush) res.flush();\r\n```\r\n\r\nI've confirmed the above by ensuring this works as expected:\r\n\r\n```javascript\r\nres.write(html);\r\nsetTimeout(function(){\r\n  if(res.flush) res.flush();\r\n}, 10);\r\n```\r\n\r\nWhat I'd prefer to do, and what this PR enables, is the following:\r\n\r\n```javascript\r\nres.write(html, null, function(){\r\n  if(res.flush) res.flush();\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/expressjs/compression/issues/comments/221178240","html_url":"https://github.com/expressjs/compression/pull/80#issuecomment-221178240","issue_url":"https://api.github.com/repos/expressjs/compression/issues/80","id":221178240,"user":{"login":"jpodwys","id":5660076,"avatar_url":"https://avatars.githubusercontent.com/u/5660076?v=3","gravatar_id":"","url":"https://api.github.com/users/jpodwys","html_url":"https://github.com/jpodwys","followers_url":"https://api.github.com/users/jpodwys/followers","following_url":"https://api.github.com/users/jpodwys/following{/other_user}","gists_url":"https://api.github.com/users/jpodwys/gists{/gist_id}","starred_url":"https://api.github.com/users/jpodwys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpodwys/subscriptions","organizations_url":"https://api.github.com/users/jpodwys/orgs","repos_url":"https://api.github.com/users/jpodwys/repos","events_url":"https://api.github.com/users/jpodwys/events{/privacy}","received_events_url":"https://api.github.com/users/jpodwys/received_events","type":"User","site_admin":false},"created_at":"2016-05-24T06:30:04Z","updated_at":"2016-05-24T06:30:04Z","body":"I prefer the first option.\r\n\r\nDoing the below, I'm able to determine whether the available `.write()` and `.end()` functions accept 3 parameters. Of course, this assumes that the person who may have overwritten an API or added a callback where there wasn't one before has also preserved the `encoding` parameter.\r\n\r\n```javascript\r\ncb = (res.write.length === 3) ? cb : noop\r\n```\r\n\r\nHowever, the tests on these node versions still fail. I'll need to download these versions and tinker some more. Regardless, is requiring that there be 3 parameters too strict?"}}
{"actor":{"display_login":"jpodwys"}}