{"action":"created","comment":{"url":"https://api.github.com/repos/sindresorhus/ky/pulls/comments/277000673","pull_request_review_id":228710365,"id":277000673,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI3NzAwMDY3Mw==","diff_hunk":"@@ -292,6 +303,46 @@ class Ky {\n \n \t\treturn timeout(fetch(this._input, this._options), this._timeout, this.abortController);\n \t}\n+\n+\t/* istanbul ignore next */\n+\t_stream(response, onProgress) {\n+\t\tconst total = Number(response.headers.get('content-length')) || 0;\n+\t\tlet transferred = 0;\n+\n+\t\treturn new Response(\n+\t\t\tnew ReadableStream({\n+\t\t\t\tstart(controller) {\n+\t\t\t\t\tconst reader = response.body.getReader();\n+\n+\t\t\t\t\tif (onProgress) {\n+\t\t\t\t\t\tonProgress(0, 0, total);\n+\t\t\t\t\t}\n+\n+\t\t\t\t\tread();\n+\t\t\t\t\tasync function read() {\n+\t\t\t\t\t\tconst {done, value} = await reader.read();\n+\t\t\t\t\t\tif (done) {\n+\t\t\t\t\t\t\tonProgress(1, transferred, total);\n+\t\t\t\t\t\t\tcontroller.close();\n+\t\t\t\t\t\t\treturn;\n+\t\t\t\t\t\t}\n+\n+\t\t\t\t\t\tif (onProgress) {\n+\t\t\t\t\t\t\ttransferred += value.byteLength;\n+\t\t\t\t\t\t\tconst percent = total === 0 ? 0 : transferred / total;\n+\n+\t\t\t\t\t\t\tif (percent !== 1) {\n+\t\t\t\t\t\t\t\tonProgress(percent, transferred, total);","path":"index.js","position":58,"original_position":58,"commit_id":"69d36af865ad34a8fdb7f07001eee195e5746cea","original_commit_id":"69d36af865ad34a8fdb7f07001eee195e5746cea","user":{"login":"szmarczak","id":36894700,"node_id":"MDQ6VXNlcjM2ODk0NzAw","avatar_url":"https://avatars0.githubusercontent.com/u/36894700?v=4","gravatar_id":"","url":"https://api.github.com/users/szmarczak","html_url":"https://github.com/szmarczak","followers_url":"https://api.github.com/users/szmarczak/followers","following_url":"https://api.github.com/users/szmarczak/following{/other_user}","gists_url":"https://api.github.com/users/szmarczak/gists{/gist_id}","starred_url":"https://api.github.com/users/szmarczak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szmarczak/subscriptions","organizations_url":"https://api.github.com/users/szmarczak/orgs","repos_url":"https://api.github.com/users/szmarczak/repos","events_url":"https://api.github.com/users/szmarczak/events{/privacy}","received_events_url":"https://api.github.com/users/szmarczak/received_events","type":"User","site_admin":false},"body":"> There's must be a good reason we did the setInterval thing in the first place, though.\r\n\r\nThe only reason I can think of is to not spam the progress events.","created_at":"2019-04-19T14:30:08Z","updated_at":"2019-04-19T14:30:08Z","html_url":"https://github.com/sindresorhus/ky/pull/34#discussion_r277000673","pull_request_url":"https://api.github.com/repos/sindresorhus/ky/pulls/34","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/comments/277000673"},"html":{"href":"https://github.com/sindresorhus/ky/pull/34#discussion_r277000673"},"pull_request":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/34"}},"in_reply_to_id":275132340},"pull_request":{"url":"https://api.github.com/repos/sindresorhus/ky/pulls/34","id":217476738,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE3NDc2NzM4","html_url":"https://github.com/sindresorhus/ky/pull/34","diff_url":"https://github.com/sindresorhus/ky/pull/34.diff","patch_url":"https://github.com/sindresorhus/ky/pull/34.patch","issue_url":"https://api.github.com/repos/sindresorhus/ky/issues/34","number":34,"state":"open","locked":false,"title":"Add `onProgress` option","user":{"login":"dangdennis","id":22418429,"node_id":"MDQ6VXNlcjIyNDE4NDI5","avatar_url":"https://avatars3.githubusercontent.com/u/22418429?v=4","gravatar_id":"","url":"https://api.github.com/users/dangdennis","html_url":"https://github.com/dangdennis","followers_url":"https://api.github.com/users/dangdennis/followers","following_url":"https://api.github.com/users/dangdennis/following{/other_user}","gists_url":"https://api.github.com/users/dangdennis/gists{/gist_id}","starred_url":"https://api.github.com/users/dangdennis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dangdennis/subscriptions","organizations_url":"https://api.github.com/users/dangdennis/orgs","repos_url":"https://api.github.com/users/dangdennis/repos","events_url":"https://api.github.com/users/dangdennis/events{/privacy}","received_events_url":"https://api.github.com/users/dangdennis/received_events","type":"User","site_admin":false},"body":"Here's the new PR for the potential stream API. \r\n\r\nBasic example for reading an image stream:\r\n```js\r\nfunction streamProgressCallback(percentage, bytes) {\r\n     console.log('percentage:: ' + percentage)\r\n     console.log('bytes:: ' + bytes)\r\n}\r\n\r\nconst res = await ky.get(someImageURL, { stream: true, streamProgressCallback }).blob();\r\n\r\nconst imgObject = URL.createObjectURL(res);\r\nconst img = document.createElement('img');\r\nimg.src = img1;\r\ndocument.body.appendChild(img)\r\n```\r\n\r\nNot sure how to test streams.\r\n\r\n---\r\n\r\nFixes #3\r\nFixes #6 ","created_at":"2018-09-22T20:25:58Z","updated_at":"2019-04-19T14:30:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e92f4d455fd23db22b1f7c50a035a97630df2bc","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/sindresorhus/ky/pulls/34/commits","review_comments_url":"https://api.github.com/repos/sindresorhus/ky/pulls/34/comments","review_comment_url":"https://api.github.com/repos/sindresorhus/ky/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sindresorhus/ky/issues/34/comments","statuses_url":"https://api.github.com/repos/sindresorhus/ky/statuses/69d36af865ad34a8fdb7f07001eee195e5746cea","head":{"label":"dangdennis:stream","ref":"stream","sha":"69d36af865ad34a8fdb7f07001eee195e5746cea","user":{"login":"dangdennis","id":22418429,"node_id":"MDQ6VXNlcjIyNDE4NDI5","avatar_url":"https://avatars3.githubusercontent.com/u/22418429?v=4","gravatar_id":"","url":"https://api.github.com/users/dangdennis","html_url":"https://github.com/dangdennis","followers_url":"https://api.github.com/users/dangdennis/followers","following_url":"https://api.github.com/users/dangdennis/following{/other_user}","gists_url":"https://api.github.com/users/dangdennis/gists{/gist_id}","starred_url":"https://api.github.com/users/dangdennis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dangdennis/subscriptions","organizations_url":"https://api.github.com/users/dangdennis/orgs","repos_url":"https://api.github.com/users/dangdennis/repos","events_url":"https://api.github.com/users/dangdennis/events{/privacy}","received_events_url":"https://api.github.com/users/dangdennis/received_events","type":"User","site_admin":false},"repo":{"id":149831154,"node_id":"MDEwOlJlcG9zaXRvcnkxNDk4MzExNTQ=","name":"ky","full_name":"dangdennis/ky","private":false,"owner":{"login":"dangdennis","id":22418429,"node_id":"MDQ6VXNlcjIyNDE4NDI5","avatar_url":"https://avatars3.githubusercontent.com/u/22418429?v=4","gravatar_id":"","url":"https://api.github.com/users/dangdennis","html_url":"https://github.com/dangdennis","followers_url":"https://api.github.com/users/dangdennis/followers","following_url":"https://api.github.com/users/dangdennis/following{/other_user}","gists_url":"https://api.github.com/users/dangdennis/gists{/gist_id}","starred_url":"https://api.github.com/users/dangdennis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dangdennis/subscriptions","organizations_url":"https://api.github.com/users/dangdennis/orgs","repos_url":"https://api.github.com/users/dangdennis/repos","events_url":"https://api.github.com/users/dangdennis/events{/privacy}","received_events_url":"https://api.github.com/users/dangdennis/received_events","type":"User","site_admin":false},"html_url":"https://github.com/dangdennis/ky","description":"Tiny and elegant HTTP client based on the browser Fetch API","fork":true,"url":"https://api.github.com/repos/dangdennis/ky","forks_url":"https://api.github.com/repos/dangdennis/ky/forks","keys_url":"https://api.github.com/repos/dangdennis/ky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dangdennis/ky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dangdennis/ky/teams","hooks_url":"https://api.github.com/repos/dangdennis/ky/hooks","issue_events_url":"https://api.github.com/repos/dangdennis/ky/issues/events{/number}","events_url":"https://api.github.com/repos/dangdennis/ky/events","assignees_url":"https://api.github.com/repos/dangdennis/ky/assignees{/user}","branches_url":"https://api.github.com/repos/dangdennis/ky/branches{/branch}","tags_url":"https://api.github.com/repos/dangdennis/ky/tags","blobs_url":"https://api.github.com/repos/dangdennis/ky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dangdennis/ky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dangdennis/ky/git/refs{/sha}","trees_url":"https://api.github.com/repos/dangdennis/ky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dangdennis/ky/statuses/{sha}","languages_url":"https://api.github.com/repos/dangdennis/ky/languages","stargazers_url":"https://api.github.com/repos/dangdennis/ky/stargazers","contributors_url":"https://api.github.com/repos/dangdennis/ky/contributors","subscribers_url":"https://api.github.com/repos/dangdennis/ky/subscribers","subscription_url":"https://api.github.com/repos/dangdennis/ky/subscription","commits_url":"https://api.github.com/repos/dangdennis/ky/commits{/sha}","git_commits_url":"https://api.github.com/repos/dangdennis/ky/git/commits{/sha}","comments_url":"https://api.github.com/repos/dangdennis/ky/comments{/number}","issue_comment_url":"https://api.github.com/repos/dangdennis/ky/issues/comments{/number}","contents_url":"https://api.github.com/repos/dangdennis/ky/contents/{+path}","compare_url":"https://api.github.com/repos/dangdennis/ky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dangdennis/ky/merges","archive_url":"https://api.github.com/repos/dangdennis/ky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dangdennis/ky/downloads","issues_url":"https://api.github.com/repos/dangdennis/ky/issues{/number}","pulls_url":"https://api.github.com/repos/dangdennis/ky/pulls{/number}","milestones_url":"https://api.github.com/repos/dangdennis/ky/milestones{/number}","notifications_url":"https://api.github.com/repos/dangdennis/ky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dangdennis/ky/labels{/name}","releases_url":"https://api.github.com/repos/dangdennis/ky/releases{/id}","deployments_url":"https://api.github.com/repos/dangdennis/ky/deployments","created_at":"2018-09-22T00:13:22Z","updated_at":"2019-01-08T22:46:00Z","pushed_at":"2019-04-09T18:51:32Z","git_url":"git://github.com/dangdennis/ky.git","ssh_url":"git@github.com:dangdennis/ky.git","clone_url":"https://github.com/dangdennis/ky.git","svn_url":"https://github.com/dangdennis/ky","homepage":"","size":353,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sindresorhus:master","ref":"master","sha":"a150ae885496a6ef307ffb65cabfd9ddaa075c40","user":{"login":"sindresorhus","id":170270,"node_id":"MDQ6VXNlcjE3MDI3MA==","avatar_url":"https://avatars1.githubusercontent.com/u/170270?v=4","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"repo":{"id":147375544,"node_id":"MDEwOlJlcG9zaXRvcnkxNDczNzU1NDQ=","name":"ky","full_name":"sindresorhus/ky","private":false,"owner":{"login":"sindresorhus","id":170270,"node_id":"MDQ6VXNlcjE3MDI3MA==","avatar_url":"https://avatars1.githubusercontent.com/u/170270?v=4","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"html_url":"https://github.com/sindresorhus/ky","description":"🌳 Tiny & elegant HTTP client based on window.fetch","fork":false,"url":"https://api.github.com/repos/sindresorhus/ky","forks_url":"https://api.github.com/repos/sindresorhus/ky/forks","keys_url":"https://api.github.com/repos/sindresorhus/ky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sindresorhus/ky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sindresorhus/ky/teams","hooks_url":"https://api.github.com/repos/sindresorhus/ky/hooks","issue_events_url":"https://api.github.com/repos/sindresorhus/ky/issues/events{/number}","events_url":"https://api.github.com/repos/sindresorhus/ky/events","assignees_url":"https://api.github.com/repos/sindresorhus/ky/assignees{/user}","branches_url":"https://api.github.com/repos/sindresorhus/ky/branches{/branch}","tags_url":"https://api.github.com/repos/sindresorhus/ky/tags","blobs_url":"https://api.github.com/repos/sindresorhus/ky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sindresorhus/ky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sindresorhus/ky/git/refs{/sha}","trees_url":"https://api.github.com/repos/sindresorhus/ky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sindresorhus/ky/statuses/{sha}","languages_url":"https://api.github.com/repos/sindresorhus/ky/languages","stargazers_url":"https://api.github.com/repos/sindresorhus/ky/stargazers","contributors_url":"https://api.github.com/repos/sindresorhus/ky/contributors","subscribers_url":"https://api.github.com/repos/sindresorhus/ky/subscribers","subscription_url":"https://api.github.com/repos/sindresorhus/ky/subscription","commits_url":"https://api.github.com/repos/sindresorhus/ky/commits{/sha}","git_commits_url":"https://api.github.com/repos/sindresorhus/ky/git/commits{/sha}","comments_url":"https://api.github.com/repos/sindresorhus/ky/comments{/number}","issue_comment_url":"https://api.github.com/repos/sindresorhus/ky/issues/comments{/number}","contents_url":"https://api.github.com/repos/sindresorhus/ky/contents/{+path}","compare_url":"https://api.github.com/repos/sindresorhus/ky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sindresorhus/ky/merges","archive_url":"https://api.github.com/repos/sindresorhus/ky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sindresorhus/ky/downloads","issues_url":"https://api.github.com/repos/sindresorhus/ky/issues{/number}","pulls_url":"https://api.github.com/repos/sindresorhus/ky/pulls{/number}","milestones_url":"https://api.github.com/repos/sindresorhus/ky/milestones{/number}","notifications_url":"https://api.github.com/repos/sindresorhus/ky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sindresorhus/ky/labels{/name}","releases_url":"https://api.github.com/repos/sindresorhus/ky/releases{/id}","deployments_url":"https://api.github.com/repos/sindresorhus/ky/deployments","created_at":"2018-09-04T16:26:42Z","updated_at":"2019-04-19T12:58:28Z","pushed_at":"2019-04-19T04:14:16Z","git_url":"git://github.com/sindresorhus/ky.git","ssh_url":"git@github.com:sindresorhus/ky.git","clone_url":"https://github.com/sindresorhus/ky.git","svn_url":"https://github.com/sindresorhus/ky","homepage":"","size":339,"stargazers_count":3857,"watchers_count":3857,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":120,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":14,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":120,"open_issues":14,"watchers":3857,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/34"},"html":{"href":"https://github.com/sindresorhus/ky/pull/34"},"issue":{"href":"https://api.github.com/repos/sindresorhus/ky/issues/34"},"comments":{"href":"https://api.github.com/repos/sindresorhus/ky/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sindresorhus/ky/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/sindresorhus/ky/statuses/69d36af865ad34a8fdb7f07001eee195e5746cea"}},"author_association":"NONE"}}
{"actor":{"display_login":"szmarczak"}}