{"action":"created","issue":{"url":"https://api.github.com/repos/koajs/koa/issues/688","repository_url":"https://api.github.com/repos/koajs/koa","labels_url":"https://api.github.com/repos/koajs/koa/issues/688/labels{/name}","comments_url":"https://api.github.com/repos/koajs/koa/issues/688/comments","events_url":"https://api.github.com/repos/koajs/koa/issues/688/events","html_url":"https://github.com/koajs/koa/issues/688","id":141832371,"number":688,"title":"response.end(body) need more parameters","user":{"login":"mailofliujin","id":6858565,"avatar_url":"https://avatars.githubusercontent.com/u/6858565?v=3","gravatar_id":"","url":"https://api.github.com/users/mailofliujin","html_url":"https://github.com/mailofliujin","followers_url":"https://api.github.com/users/mailofliujin/followers","following_url":"https://api.github.com/users/mailofliujin/following{/other_user}","gists_url":"https://api.github.com/users/mailofliujin/gists{/gist_id}","starred_url":"https://api.github.com/users/mailofliujin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mailofliujin/subscriptions","organizations_url":"https://api.github.com/users/mailofliujin/orgs","repos_url":"https://api.github.com/users/mailofliujin/repos","events_url":"https://api.github.com/users/mailofliujin/events{/privacy}","received_events_url":"https://api.github.com/users/mailofliujin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-18T10:46:09Z","updated_at":"2016-03-18T10:51:53Z","closed_at":"2016-03-18T10:51:53Z","body":"We want to read a file and show it directly in browser.\r\n\r\nWhen I use this command, the image is not showing.\r\nthis.body = fs.readFileSync('a.jpg','binary');  //any file, sometimes it's from db eg.redis\r\n\r\nSo I have added some lines to kao/lib/response.js:\r\n  set encoding(val){\r\n      this.encoding = val;\r\n  },\r\n\r\nand change kao/lib/application.js:\r\n  if ('string' == typeof body) {\r\n      return res.end(body, this.encoding);\r\n  }\r\n\r\nnow it works. \r\nthis.encoding = 'binary';\r\nthis.body = fs.readFileSync('a.jpg','binary');\r\n"},"comment":{"url":"https://api.github.com/repos/koajs/koa/issues/comments/198303717","html_url":"https://github.com/koajs/koa/issues/688#issuecomment-198303717","issue_url":"https://api.github.com/repos/koajs/koa/issues/688","id":198303717,"user":{"login":"juliangruber","id":10247,"avatar_url":"https://avatars.githubusercontent.com/u/10247?v=3","gravatar_id":"","url":"https://api.github.com/users/juliangruber","html_url":"https://github.com/juliangruber","followers_url":"https://api.github.com/users/juliangruber/followers","following_url":"https://api.github.com/users/juliangruber/following{/other_user}","gists_url":"https://api.github.com/users/juliangruber/gists{/gist_id}","starred_url":"https://api.github.com/users/juliangruber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliangruber/subscriptions","organizations_url":"https://api.github.com/users/juliangruber/orgs","repos_url":"https://api.github.com/users/juliangruber/repos","events_url":"https://api.github.com/users/juliangruber/events{/privacy}","received_events_url":"https://api.github.com/users/juliangruber/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T10:51:53Z","updated_at":"2016-03-18T10:51:53Z","body":"try not passing `'binary'` to fs.readFileSync. This option will return a binary string, which is way less efficient than the buffer that `fs.readFileSync` is returning by default.\r\n\r\nAlso you shouldn't use a *Sync function call inside a koa handler as it will block the whole process while the file is being read. Try using a promise fs wrapper."}}