{"action":"created","issue":{"url":"https://api.github.com/repos/lovell/sharp/issues/560","repository_url":"https://api.github.com/repos/lovell/sharp","labels_url":"https://api.github.com/repos/lovell/sharp/issues/560/labels{/name}","comments_url":"https://api.github.com/repos/lovell/sharp/issues/560/comments","events_url":"https://api.github.com/repos/lovell/sharp/issues/560/events","html_url":"https://github.com/lovell/sharp/issues/560","id":174289895,"number":560,"title":"Feature Reqest: metadata callback value prevents toFile","user":{"login":"rahbari","id":163890,"avatar_url":"https://avatars.githubusercontent.com/u/163890?v=3","gravatar_id":"","url":"https://api.github.com/users/rahbari","html_url":"https://github.com/rahbari","followers_url":"https://api.github.com/users/rahbari/followers","following_url":"https://api.github.com/users/rahbari/following{/other_user}","gists_url":"https://api.github.com/users/rahbari/gists{/gist_id}","starred_url":"https://api.github.com/users/rahbari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rahbari/subscriptions","organizations_url":"https://api.github.com/users/rahbari/orgs","repos_url":"https://api.github.com/users/rahbari/repos","events_url":"https://api.github.com/users/rahbari/events{/privacy}","received_events_url":"https://api.github.com/users/rahbari/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lovell/sharp/labels/question","name":"question","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-08-31T14:34:24Z","updated_at":"2016-09-03T20:55:30Z","closed_at":null,"body":"When piping data there it's not possible to execute toBuffer in metadata callback:\r\n\r\n```\r\nimg = sh();\r\nimg.webp().quality(75)\r\n\t.metadata((err, data) => {     // check image dims before processing\r\n\t\tif (err) return res.json({err});\r\n\t\timg.toFile('uploads/img', (err) => {\r\n\t\t\tres.json({err});\r\n\t\t})\r\n\t});\r\nreq.pipe(img);\r\n```\r\nin above example toFile is never called because of piping.\r\n\r\nBut when they are chained both of them work, so it would be nice if metadata callback returns false toFile execution is prevented.\r\n\r\n```\r\nimg = sh();\r\nimg.webp().quality(75)\t\r\n\t.metadata((err, data) => {    // check image dims before processing\r\n\t\tif (err) return false; // this must prevent toFile execution\r\n\t})\r\n\t.toFile('uploads/img', (err) => {\r\n\t\tres.json({err});\r\n\t});\r\nreq.pipe(img);\r\n```\r\n\r\nI don't know if there is another way to do it now other than buffering data!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/lovell/sharp/issues/comments/244569334","html_url":"https://github.com/lovell/sharp/issues/560#issuecomment-244569334","issue_url":"https://api.github.com/repos/lovell/sharp/issues/560","id":244569334,"user":{"login":"rahbari","id":163890,"avatar_url":"https://avatars.githubusercontent.com/u/163890?v=3","gravatar_id":"","url":"https://api.github.com/users/rahbari","html_url":"https://github.com/rahbari","followers_url":"https://api.github.com/users/rahbari/followers","following_url":"https://api.github.com/users/rahbari/following{/other_user}","gists_url":"https://api.github.com/users/rahbari/gists{/gist_id}","starred_url":"https://api.github.com/users/rahbari/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rahbari/subscriptions","organizations_url":"https://api.github.com/users/rahbari/orgs","repos_url":"https://api.github.com/users/rahbari/repos","events_url":"https://api.github.com/users/rahbari/events{/privacy}","received_events_url":"https://api.github.com/users/rahbari/received_events","type":"User","site_admin":false},"created_at":"2016-09-03T20:55:30Z","updated_at":"2016-09-03T20:55:30Z","body":"@lovell I tested, doesn't work! toFile is never called!"}}
{"actor":{"display_login":"rahbari"}}