{"action":"created","comment":{"url":"https://api.github.com/repos/koajs/sendfile/pulls/comments/42930811","id":42930811,"diff_hunk":"@@ -24,18 +24,22 @@ It does not:\n \n ## API\n \n-### var stats = yield* sendfile.call(this, filename)\n+### sendfile(context, filename)\n \n-You must pass `this` as the context. `filename` is the filename of the file.\n+You must pass the koa context. `filename` is the filename of the file.\n \n-`stats` is the `fs.stat()` result of the filename. If `stats` exists, that doesn't mean that a response is set - the filename could be a directory. Instead, check `if (this.status)`.\n+sendfile returns a promise that resolves to the `fs.stat()` result of the filename. If sendfile() resolves, that doesn't mean that a response is set - the filename could be a directory. Instead, check `if (context.status)`.\n \n ```js\n var sendfile = require('koa-sendfile')\n \n app.use(function* (next) {\n-  var stats = yield* sendfile.call(this, '/Users/jong/.bash_profile')\n-  if (!this.status) this.throw(404)\n+  var context = this;\n+  sendfile(this, '/Users/jong/.bash_profile')\n+  .then(function(){\n+    if (!context.status) context.throw(404)\n+  })\n+  .catch(context.throw.bind(context))\n })","path":"README.md","position":25,"original_position":25,"commit_id":"b52ca91296e286dff53cbe413cd220a879fc9c0e","original_commit_id":"b52ca91296e286dff53cbe413cd220a879fc9c0e","user":{"login":"coderhaoxin","id":2569835,"avatar_url":"https://avatars.githubusercontent.com/u/2569835?v=3","gravatar_id":"","url":"https://api.github.com/users/coderhaoxin","html_url":"https://github.com/coderhaoxin","followers_url":"https://api.github.com/users/coderhaoxin/followers","following_url":"https://api.github.com/users/coderhaoxin/following{/other_user}","gists_url":"https://api.github.com/users/coderhaoxin/gists{/gist_id}","starred_url":"https://api.github.com/users/coderhaoxin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coderhaoxin/subscriptions","organizations_url":"https://api.github.com/users/coderhaoxin/orgs","repos_url":"https://api.github.com/users/coderhaoxin/repos","events_url":"https://api.github.com/users/coderhaoxin/events{/privacy}","received_events_url":"https://api.github.com/users/coderhaoxin/received_events","type":"User","site_admin":false},"body":"\r\n```js\r\nvar context = this;\r\nvar stats = yield sendfile(context, '/Users/jong/.bash_profile')\r\nif (!this.status) this.throw(404)\r\n```\r\n\r\n","created_at":"2015-10-24T06:02:49Z","updated_at":"2015-10-24T06:02:49Z","html_url":"https://github.com/koajs/sendfile/pull/3#discussion_r42930811","pull_request_url":"https://api.github.com/repos/koajs/sendfile/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/comments/42930811"},"html":{"href":"https://github.com/koajs/sendfile/pull/3#discussion_r42930811"},"pull_request":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/koajs/sendfile/pulls/3","id":48623008,"html_url":"https://github.com/koajs/sendfile/pull/3","diff_url":"https://github.com/koajs/sendfile/pull/3.diff","patch_url":"https://github.com/koajs/sendfile/pull/3.patch","issue_url":"https://api.github.com/repos/koajs/sendfile/issues/3","number":3,"state":"open","locked":false,"title":"Convert from generator to promise.","user":{"login":"smcmurray","id":1036479,"avatar_url":"https://avatars.githubusercontent.com/u/1036479?v=3","gravatar_id":"","url":"https://api.github.com/users/smcmurray","html_url":"https://github.com/smcmurray","followers_url":"https://api.github.com/users/smcmurray/followers","following_url":"https://api.github.com/users/smcmurray/following{/other_user}","gists_url":"https://api.github.com/users/smcmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/smcmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smcmurray/subscriptions","organizations_url":"https://api.github.com/users/smcmurray/orgs","repos_url":"https://api.github.com/users/smcmurray/repos","events_url":"https://api.github.com/users/smcmurray/events{/privacy}","received_events_url":"https://api.github.com/users/smcmurray/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-23T19:55:55Z","updated_at":"2015-10-24T06:02:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3de07b00f97ff75ff2cb33f137d21fba44f45cc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/koajs/sendfile/pulls/3/commits","review_comments_url":"https://api.github.com/repos/koajs/sendfile/pulls/3/comments","review_comment_url":"https://api.github.com/repos/koajs/sendfile/pulls/comments{/number}","comments_url":"https://api.github.com/repos/koajs/sendfile/issues/3/comments","statuses_url":"https://api.github.com/repos/koajs/sendfile/statuses/b52ca91296e286dff53cbe413cd220a879fc9c0e","head":{"label":"smcmurray:promise","ref":"promise","sha":"b52ca91296e286dff53cbe413cd220a879fc9c0e","user":{"login":"smcmurray","id":1036479,"avatar_url":"https://avatars.githubusercontent.com/u/1036479?v=3","gravatar_id":"","url":"https://api.github.com/users/smcmurray","html_url":"https://github.com/smcmurray","followers_url":"https://api.github.com/users/smcmurray/followers","following_url":"https://api.github.com/users/smcmurray/following{/other_user}","gists_url":"https://api.github.com/users/smcmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/smcmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smcmurray/subscriptions","organizations_url":"https://api.github.com/users/smcmurray/orgs","repos_url":"https://api.github.com/users/smcmurray/repos","events_url":"https://api.github.com/users/smcmurray/events{/privacy}","received_events_url":"https://api.github.com/users/smcmurray/received_events","type":"User","site_admin":false},"repo":{"id":44833876,"name":"sendfile","full_name":"smcmurray/sendfile","owner":{"login":"smcmurray","id":1036479,"avatar_url":"https://avatars.githubusercontent.com/u/1036479?v=3","gravatar_id":"","url":"https://api.github.com/users/smcmurray","html_url":"https://github.com/smcmurray","followers_url":"https://api.github.com/users/smcmurray/followers","following_url":"https://api.github.com/users/smcmurray/following{/other_user}","gists_url":"https://api.github.com/users/smcmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/smcmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smcmurray/subscriptions","organizations_url":"https://api.github.com/users/smcmurray/orgs","repos_url":"https://api.github.com/users/smcmurray/repos","events_url":"https://api.github.com/users/smcmurray/events{/privacy}","received_events_url":"https://api.github.com/users/smcmurray/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smcmurray/sendfile","description":"basic file-sending utility for koa","fork":true,"url":"https://api.github.com/repos/smcmurray/sendfile","forks_url":"https://api.github.com/repos/smcmurray/sendfile/forks","keys_url":"https://api.github.com/repos/smcmurray/sendfile/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smcmurray/sendfile/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smcmurray/sendfile/teams","hooks_url":"https://api.github.com/repos/smcmurray/sendfile/hooks","issue_events_url":"https://api.github.com/repos/smcmurray/sendfile/issues/events{/number}","events_url":"https://api.github.com/repos/smcmurray/sendfile/events","assignees_url":"https://api.github.com/repos/smcmurray/sendfile/assignees{/user}","branches_url":"https://api.github.com/repos/smcmurray/sendfile/branches{/branch}","tags_url":"https://api.github.com/repos/smcmurray/sendfile/tags","blobs_url":"https://api.github.com/repos/smcmurray/sendfile/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smcmurray/sendfile/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smcmurray/sendfile/git/refs{/sha}","trees_url":"https://api.github.com/repos/smcmurray/sendfile/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smcmurray/sendfile/statuses/{sha}","languages_url":"https://api.github.com/repos/smcmurray/sendfile/languages","stargazers_url":"https://api.github.com/repos/smcmurray/sendfile/stargazers","contributors_url":"https://api.github.com/repos/smcmurray/sendfile/contributors","subscribers_url":"https://api.github.com/repos/smcmurray/sendfile/subscribers","subscription_url":"https://api.github.com/repos/smcmurray/sendfile/subscription","commits_url":"https://api.github.com/repos/smcmurray/sendfile/commits{/sha}","git_commits_url":"https://api.github.com/repos/smcmurray/sendfile/git/commits{/sha}","comments_url":"https://api.github.com/repos/smcmurray/sendfile/comments{/number}","issue_comment_url":"https://api.github.com/repos/smcmurray/sendfile/issues/comments{/number}","contents_url":"https://api.github.com/repos/smcmurray/sendfile/contents/{+path}","compare_url":"https://api.github.com/repos/smcmurray/sendfile/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smcmurray/sendfile/merges","archive_url":"https://api.github.com/repos/smcmurray/sendfile/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smcmurray/sendfile/downloads","issues_url":"https://api.github.com/repos/smcmurray/sendfile/issues{/number}","pulls_url":"https://api.github.com/repos/smcmurray/sendfile/pulls{/number}","milestones_url":"https://api.github.com/repos/smcmurray/sendfile/milestones{/number}","notifications_url":"https://api.github.com/repos/smcmurray/sendfile/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smcmurray/sendfile/labels{/name}","releases_url":"https://api.github.com/repos/smcmurray/sendfile/releases{/id}","created_at":"2015-10-23T19:26:03Z","updated_at":"2015-10-23T19:26:04Z","pushed_at":"2015-10-24T00:44:51Z","git_url":"git://github.com/smcmurray/sendfile.git","ssh_url":"git@github.com:smcmurray/sendfile.git","clone_url":"https://github.com/smcmurray/sendfile.git","svn_url":"https://github.com/smcmurray/sendfile","homepage":null,"size":86,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"koajs:master","ref":"master","sha":"f2a61b0913d7a83b74d8132badc3a56ff546df42","user":{"login":"koajs","id":5055057,"avatar_url":"https://avatars.githubusercontent.com/u/5055057?v=3","gravatar_id":"","url":"https://api.github.com/users/koajs","html_url":"https://github.com/koajs","followers_url":"https://api.github.com/users/koajs/followers","following_url":"https://api.github.com/users/koajs/following{/other_user}","gists_url":"https://api.github.com/users/koajs/gists{/gist_id}","starred_url":"https://api.github.com/users/koajs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koajs/subscriptions","organizations_url":"https://api.github.com/users/koajs/orgs","repos_url":"https://api.github.com/users/koajs/repos","events_url":"https://api.github.com/users/koajs/events{/privacy}","received_events_url":"https://api.github.com/users/koajs/received_events","type":"Organization","site_admin":false},"repo":{"id":18031787,"name":"sendfile","full_name":"koajs/sendfile","owner":{"login":"koajs","id":5055057,"avatar_url":"https://avatars.githubusercontent.com/u/5055057?v=3","gravatar_id":"","url":"https://api.github.com/users/koajs","html_url":"https://github.com/koajs","followers_url":"https://api.github.com/users/koajs/followers","following_url":"https://api.github.com/users/koajs/following{/other_user}","gists_url":"https://api.github.com/users/koajs/gists{/gist_id}","starred_url":"https://api.github.com/users/koajs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koajs/subscriptions","organizations_url":"https://api.github.com/users/koajs/orgs","repos_url":"https://api.github.com/users/koajs/repos","events_url":"https://api.github.com/users/koajs/events{/privacy}","received_events_url":"https://api.github.com/users/koajs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/koajs/sendfile","description":"basic file-sending utility for koa","fork":false,"url":"https://api.github.com/repos/koajs/sendfile","forks_url":"https://api.github.com/repos/koajs/sendfile/forks","keys_url":"https://api.github.com/repos/koajs/sendfile/keys{/key_id}","collaborators_url":"https://api.github.com/repos/koajs/sendfile/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/koajs/sendfile/teams","hooks_url":"https://api.github.com/repos/koajs/sendfile/hooks","issue_events_url":"https://api.github.com/repos/koajs/sendfile/issues/events{/number}","events_url":"https://api.github.com/repos/koajs/sendfile/events","assignees_url":"https://api.github.com/repos/koajs/sendfile/assignees{/user}","branches_url":"https://api.github.com/repos/koajs/sendfile/branches{/branch}","tags_url":"https://api.github.com/repos/koajs/sendfile/tags","blobs_url":"https://api.github.com/repos/koajs/sendfile/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/koajs/sendfile/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/koajs/sendfile/git/refs{/sha}","trees_url":"https://api.github.com/repos/koajs/sendfile/git/trees{/sha}","statuses_url":"https://api.github.com/repos/koajs/sendfile/statuses/{sha}","languages_url":"https://api.github.com/repos/koajs/sendfile/languages","stargazers_url":"https://api.github.com/repos/koajs/sendfile/stargazers","contributors_url":"https://api.github.com/repos/koajs/sendfile/contributors","subscribers_url":"https://api.github.com/repos/koajs/sendfile/subscribers","subscription_url":"https://api.github.com/repos/koajs/sendfile/subscription","commits_url":"https://api.github.com/repos/koajs/sendfile/commits{/sha}","git_commits_url":"https://api.github.com/repos/koajs/sendfile/git/commits{/sha}","comments_url":"https://api.github.com/repos/koajs/sendfile/comments{/number}","issue_comment_url":"https://api.github.com/repos/koajs/sendfile/issues/comments{/number}","contents_url":"https://api.github.com/repos/koajs/sendfile/contents/{+path}","compare_url":"https://api.github.com/repos/koajs/sendfile/compare/{base}...{head}","merges_url":"https://api.github.com/repos/koajs/sendfile/merges","archive_url":"https://api.github.com/repos/koajs/sendfile/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/koajs/sendfile/downloads","issues_url":"https://api.github.com/repos/koajs/sendfile/issues{/number}","pulls_url":"https://api.github.com/repos/koajs/sendfile/pulls{/number}","milestones_url":"https://api.github.com/repos/koajs/sendfile/milestones{/number}","notifications_url":"https://api.github.com/repos/koajs/sendfile/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/koajs/sendfile/labels{/name}","releases_url":"https://api.github.com/repos/koajs/sendfile/releases{/id}","created_at":"2014-03-23T11:22:26Z","updated_at":"2015-10-10T07:55:22Z","pushed_at":"2015-10-24T00:44:51Z","git_url":"git://github.com/koajs/sendfile.git","ssh_url":"git@github.com:koajs/sendfile.git","clone_url":"https://github.com/koajs/sendfile.git","svn_url":"https://github.com/koajs/sendfile","homepage":null,"size":163,"stargazers_count":11,"watchers_count":11,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/3"},"html":{"href":"https://github.com/koajs/sendfile/pull/3"},"issue":{"href":"https://api.github.com/repos/koajs/sendfile/issues/3"},"comments":{"href":"https://api.github.com/repos/koajs/sendfile/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/koajs/sendfile/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/koajs/sendfile/statuses/b52ca91296e286dff53cbe413cd220a879fc9c0e"}}}}