Skip to content

Commit

Permalink
oh GFM, you mock me!
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 10, 2013
1 parent 49de57a commit 84eee24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ const fdman = require('fd')()

// an async cache for fs.stat calls, fresh for 10s
, statCache = AC({
max : 10
, maxAge : 1000
max : 100
, maxAge : 10000
, load : function (path, callback) {
fs.stat(path, callback)
}
})

// an async cache for fds, fresh for 10s
, fdCache = AC({
max : 2
, maxAge : 1000
max : 100
, maxAge : 10000
// use fdman to open & close
, load : fdman.open.bind(fdman)
, dispose : fdman.close.bind(fdman)
Expand Down Expand Up @@ -75,12 +75,8 @@ http.createServer(function (req, res) {

// stream from the fd to the response
var st = fs.createReadStream(p, { fd: fd, start: 0, end: stat.size })
.on('end', function () {
checkin(p, fd)
})
.on('error', function () {
checkin(p, fd)
})
.on('end', checkin)
.on('error', checkin)

// override destroy so we don't close the fd
st.destroy = function () {}
Expand All @@ -89,7 +85,8 @@ http.createServer(function (req, res) {

})
})
}).listen(8080)```
}).listen(8080)
```

## API

Expand Down
16 changes: 6 additions & 10 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const fdman = require('../')()

// an async cache for fs.stat calls, fresh for 10s
, statCache = AC({
max : 10
, maxAge : 1000
max : 100
, maxAge : 10000
, load : function (path, callback) {
fs.stat(path, callback)
}
})

// an async cache for fds, fresh for 10s
, fdCache = AC({
max : 2
, maxAge : 1000
max : 100
, maxAge : 10000
// use fdman to open & close
, load : fdman.open.bind(fdman)
, dispose : fdman.close.bind(fdman)
Expand Down Expand Up @@ -63,12 +63,8 @@ http.createServer(function (req, res) {

// stream from the fd to the response
var st = fs.createReadStream(p, { fd: fd, start: 0, end: stat.size })
.on('end', function () {
checkin(p, fd)
})
.on('error', function () {
checkin(p, fd)
})
.on('end', checkin)
.on('error', checkin)

// override destroy so we don't close the fd
st.destroy = function () {}
Expand Down

0 comments on commit 84eee24

Please sign in to comment.