New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-sendfile

Package Overview
Dependencies
Maintainers
10
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-sendfile - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

48

index.js

@@ -1,14 +0,18 @@

var extname = require('path').extname
var calculate = require('etag')
var fs = require('mz/fs')
const promisify = require('util').promisify
const extname = require('path').extname
const fs = require('fs')
const calculate = require('etag')
var notfound = {
const stat = promisify(fs.stat)
const notfound = {
ENOENT: true,
ENAMETOOLONG: true,
ENOTDIR: true,
ENOTDIR: true
}
module.exports = function sendfile(ctx, path) {
return fs.stat(path)
.then(function(stats){
module.exports = async function sendfile (ctx, path) {
try {
const stats = await stat(path)
if (!stats) return null

@@ -21,15 +25,17 @@ if (!stats.isFile()) return stats

ctx.response.type = extname(path)
if (!ctx.response.etag) ctx.response.etag = calculate(stats, {
weak: true
})
if (!ctx.response.etag) {
ctx.response.etag = calculate(stats, {
weak: true
})
}
// fresh based solely on last-modified
var fresh = ctx.request.fresh
switch (ctx.request.method) {
case 'HEAD':
ctx.response.status = fresh ? 304 : 200
ctx.status = ctx.request.fresh ? 304 : 200
break
case 'GET':
if (fresh) {
ctx.response.status = 304
if (ctx.request.fresh) {
ctx.status = 304
} else {

@@ -42,9 +48,7 @@ ctx.body = fs.createReadStream(path)

return stats
}, onstaterror);
} catch (err) {
if (notfound[err.code]) return
err.status = 500
throw err
}
}
function onstaterror(err) {
if (notfound[err.code]) return
err.status = 500
throw err
}
{
"name": "koa-sendfile",
"version": "3.0.0",
"description": "basic file-sending utility for koa",
"version": "2.0.1",
"files": [
"index.js"
],
"repository": "koajs/sendfile",
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "mocha --r should --exit",
"precoverage": "rimraf .nyc_output coverage",
"coverage": "nyc npm run test",
"ci": "npm run coverage"
},
"author": {

@@ -11,27 +23,23 @@ "name": "Jonathan Ong",

},
"repository": "koajs/sendfile",
"license": "MIT",
"dependencies": {
"debug": "^3.2.5",
"etag": "^1.5.1",
"mz": "2"
"debug": "^4.2.0",
"etag": "^1.8.1"
},
"devDependencies": {
"istanbul": "0",
"koa": "1",
"should": "8",
"mocha": "2",
"supertest": "1"
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"koa": "^2.13.0",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"should": "^13.2.3",
"supertest": "^4.0.2"
},
"scripts": {
"test": "NODE_ENV=test mocha --harmony --require should --reporter spec",
"test-cov": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --require should",
"test-travis": "NODE_ENV=test node --harmony ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should"
},
"engines": {
"node": ">= 0.12"
},
"files": [
"index.js"
],
"license": "MIT"
"node": ">= 10"
}
}

@@ -1,2 +0,1 @@

# koa sendfile

@@ -34,7 +33,7 @@

```js
var sendfile = require('koa-sendfile')
const sendfile = require('koa-sendfile')
app.use(function* (next) {
var stats = yield sendfile(this, '/Users/jong/.bash_profile')
if (!this.status) this.throw(404)
app.use(async function (ctx, next) {
const stats = await sendfile(ctx, '/Users/jong/.bash_profile')
if (!ctx.status) ctx.throw(404)
})

@@ -41,0 +40,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc