{"id":13779933,"url":"https://github.com/koajs/sendfile","last_synced_at":"2025-10-19T13:31:33.379Z","repository":{"id":15302018,"uuid":"18031787","full_name":"koajs/sendfile","owner":"koajs","description":"basic file-sending utility for koa","archived":false,"fork":false,"pushed_at":"2023-01-16T13:08:02.000Z","size":28,"stargazers_count":49,"open_issues_count":6,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T15:32:19.474Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koajs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-23T11:22:26.000Z","updated_at":"2024-07-19T23:47:58.000Z","dependencies_parsed_at":"2023-02-10T03:31:11.811Z","dependency_job_id":null,"html_url":"https://github.com/koajs/sendfile","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsendfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsendfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsendfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koajs%2Fsendfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koajs","download_url":"https://codeload.github.com/koajs/sendfile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237133591,"owners_count":19260506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:10.689Z","updated_at":"2025-10-19T13:31:28.088Z","avatar_url":"https://github.com/koajs.png","language":"JavaScript","readme":"# koa sendfile\n\n[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Dependency Status][david-image]][david-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\nBasic file-sending utility for koa. It does the following:\n\n- Check if a file exists\n- Set content-length, content-type, and last-modified headers\n- 304 based on last-modified\n- Handle HEAD requests\n\nIt does not:\n\n- Check for malicious paths or hidden files\n- Support directory indexes\n- Cache control\n- OPTIONS method\n\n## API\n\n### sendfile(context, filename)\n\nYou must pass the koa context. `filename` is the filename of the file.\n\nsendfile 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\nconst sendfile = require('koa-sendfile')\n\napp.use(async function (ctx, next) {\n  const stats = await sendfile(ctx, '/Users/jong/.bash_profile')\n  if (!ctx.status) ctx.throw(404)\n})\n```\n\n[npm-image]: https://img.shields.io/npm/v/koa-sendfile.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-sendfile\n[github-tag]: http://img.shields.io/github/tag/koajs/sendfile.svg?style=flat-square\n[github-url]: https://github.com/koajs/sendfile/tags\n[travis-image]: https://img.shields.io/travis/koajs/sendfile.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/sendfile\n[coveralls-image]: https://img.shields.io/coveralls/koajs/sendfile.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/sendfile?branch=master\n[david-image]: http://img.shields.io/david/koajs/sendfile.svg?style=flat-square\n[david-url]: https://david-dm.org/koajs/sendfile\n[license-image]: http://img.shields.io/npm/l/koa-sendfile.svg?style=flat-square\n[license-url]: LICENSE\n[downloads-image]: http://img.shields.io/npm/dm/koa-sendfile.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/koa-sendfile\n","funding_links":[],"categories":["Middleware","仓库"],"sub_categories":["中间件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fsendfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoajs%2Fsendfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoajs%2Fsendfile/lists"}