Comparing version 0.0.1 to 0.0.2
@@ -46,2 +46,3 @@ var fs = require('fs') | ||
var finish = function (err, stats) { | ||
if (err && err.code === 'ENOENT' && !self.dest && !self.src) self.src = self.path | ||
if (err && !self.dest && !self.src) return self.emit('error', err) | ||
@@ -76,6 +77,6 @@ if (err && self.dest && !self.dest.writeHead) return self.emit('error', err) | ||
self.dest.statusCode = 404 | ||
self.end('Not Found') | ||
self.dest.end('Not Found') | ||
} else { | ||
self.dest.statusCode = 500 | ||
self.end(err.message) | ||
self.dest.end(err.message) | ||
} | ||
@@ -96,3 +97,3 @@ return | ||
// Lazy last-modifed matching but it's faster than parsing Datetime | ||
self.src.headers['if-modifified-since'] === self.lastmodified) { | ||
self.src.headers['if-modified-since'] === self.lastmodified) { | ||
self.dest.statusCode = 304 | ||
@@ -99,0 +100,0 @@ self.dest.end() |
{ | ||
"name": "filed", | ||
"description": "Simplified file library.", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": { | ||
@@ -13,3 +13,4 @@ "type": "git", | ||
}, | ||
"scripts": {"test": "node test/test.js"}, | ||
"main": "./main" | ||
} | ||
} |
@@ -11,6 +11,6 @@ # filed -- Simplified file library. | ||
Filed does a lazy stat call so you can actually open a file and being writing to it and if the file isn't there it will just be created. | ||
Filed does a lazy stat call so you can actually open a file and begin writing to it and if the file isn't there it will just be created. | ||
```javascript | ||
var request = require('filed'); | ||
var filed = require('filed'); | ||
var f = filed('/newfile') | ||
@@ -28,3 +28,3 @@ f.write('test') | ||
```javascript | ||
fs.createReadStream(filed('/newfile')) | ||
fs.createReadStream.pipe(filed('/newfile')) | ||
``` | ||
@@ -70,3 +70,3 @@ | ||
The Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken in to account a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads. | ||
The Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken into account; a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads. | ||
@@ -79,2 +79,2 @@ ```javascript | ||
Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists. | ||
Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists. |
@@ -139,2 +139,8 @@ var filed = require('../main') | ||
s.on('/test-not-found', function (req, resp) { | ||
var x = filed(__dirname + "/there-is-no-such-file-here.no-extension") | ||
req.pipe(x) | ||
x.pipe(resp) | ||
}) | ||
s.listen(port, function () { | ||
@@ -170,3 +176,3 @@ | ||
if (resp.statusCode !== 200) throw new Error('Status code is not 200 it is '+resp.statusCode) | ||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modifified-since':resp.headers['last-modified']}}, function (e, resp) { | ||
request.get({url:url+'/test-lastmodified-with', headers:{'if-modified-since':resp.headers['last-modified']}}, function (e, resp) { | ||
if (e) throw e | ||
@@ -194,2 +200,8 @@ if (resp.statusCode !== 304) throw new Error('Status code is not 304 it is '+resp.statusCode) | ||
request.get(url+'/test-not-found', function (e, resp, body) { | ||
if (e) throw e | ||
if (resp.statusCode !== 404) throw new Error('Status code is not 404 it is '+resp.statusCode) | ||
console.log("Passed Not Found produces 404") | ||
}) | ||
}) | ||
@@ -196,0 +208,0 @@ |
38115
543
77