connect-static
Advanced tools
Comparing version 1.1.1 to 1.2.0
24
index.js
@@ -10,3 +10,3 @@ var zlib = require('zlib'); | ||
var url = require('url'); | ||
var StreamSink = require('streamsink'); | ||
var BufferList = require('bl'); | ||
var crypto = require('crypto'); | ||
@@ -28,3 +28,3 @@ | ||
var relName = '/' + path.relative(dir, file); | ||
var sink = new StreamSink(); | ||
var bl = new BufferList(); | ||
var inStream = fs.createReadStream(file); | ||
@@ -41,3 +41,3 @@ inStream.on('error', function(err) { | ||
cache[relName] = cacheObj = { | ||
sink: sink, | ||
bl: bl, | ||
mime: mime.lookup(relName), | ||
@@ -48,10 +48,10 @@ mtime: stat.mtime, | ||
pend.go(function(cb) { | ||
inStream.pipe(zlib.createGzip()).pipe(sink); | ||
sink.once('finish', cb); | ||
inStream.pipe(zlib.createGzip()).pipe(bl); | ||
bl.once('finish', cb); | ||
}); | ||
pend.go(function(cb) { | ||
var hashSink = new StreamSink(); | ||
inStream.pipe(crypto.createHash('sha1')).pipe(hashSink); | ||
hashSink.once('finish', function() { | ||
cacheObj.hash = hashSink.toString('base64'); | ||
var hashBl = new BufferList(); | ||
inStream.pipe(crypto.createHash('sha1')).pipe(hashBl); | ||
hashBl.once('finish', function() { | ||
cacheObj.hash = hashBl.toString('base64'); | ||
cb(); | ||
@@ -85,10 +85,10 @@ }); | ||
var sink = c.sink; | ||
var bl = c.bl; | ||
resp.setHeader('Content-Type', c.mime); | ||
resp.setHeader('ETag', c.hash); | ||
if (req.headers['accept-encoding'] == null) { | ||
sink.createReadStream().pipe(zlib.createGunzip()).pipe(resp); | ||
bl.duplicate().pipe(zlib.createGunzip()).pipe(resp); | ||
} else { | ||
resp.setHeader('Content-Encoding', 'gzip'); | ||
sink.createReadStream().pipe(resp); | ||
bl.duplicate().pipe(resp); | ||
} | ||
@@ -95,0 +95,0 @@ } |
{ | ||
"name": "connect-static", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "static file server middleware for connect. loads files once at startup and saves gzipped versions in memory", | ||
@@ -20,7 +20,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"streamsink": "~1.0.1", | ||
"pend": "~1.1.1", | ||
"bl": "~0.8.2", | ||
"findit": "~1.1.1", | ||
"mime": "~1.2.11" | ||
"mime": "~1.2.11", | ||
"pend": "~1.1.1" | ||
} | ||
} |
@@ -8,2 +8,5 @@ # static caching gzipping file server middleware for connect | ||
Are you looking for the middleware that used to ship with express and connect? | ||
That project is called [serve-static](https://github.com/expressjs/serve-static) | ||
## Supported HTTP Headers | ||
@@ -10,0 +13,0 @@ |
var createStatic = require('..'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var StreamSink = require('streamsink'); | ||
var BufferList = require('bl'); | ||
@@ -11,13 +11,13 @@ var dir = path.join(__dirname, "public"); | ||
middleware({url: '/unrelated'}, null, function() { | ||
var sink = new StreamSink(); | ||
sink.on('finish', function() { | ||
assert.strictEqual(sink.buffer[0].toString(), "hi\n") | ||
var bl = new BufferList(); | ||
bl.on('finish', function() { | ||
assert.strictEqual(bl._bufs[0].toString(), "hi\n") | ||
console.log("OK"); | ||
}); | ||
sink.setHeader = function(name, val) {}; | ||
bl.setHeader = function(name, val) {}; | ||
middleware({ | ||
url: '/foo.txt', | ||
headers: {}, | ||
}, sink, assert.fail) | ||
}, bl, assert.fail) | ||
}); | ||
}); |
5079
40
+ Addedbl@~0.8.2
+ Addedbl@0.8.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)
- Removedstreamsink@~1.0.1
- Removedstreamsink@1.0.1(transitive)