Read file with LRU caching, rely on thunks.
npm install file-cacheRead file with LRU caching, rely on thunks.
[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Downloads][downloads-image]][downloads-url]
``js
const FileCache = require('file-cache')
const fileCache = FileCache('./')
fileCache('index.js')(function (err, file) {
console.log(err, file)
// { path: '/Users/zensh/git/toajs/file-cache/index.js',
// dir: '/Users/zensh/git/toajs/file-cache',
// name: 'index.js',
// ext: '.js',
// type: 'application/javascript',
// size: 4375,
// atime: 'Sun, 30 Nov 2014 03:38:25 GMT',
// mtime: 'Sun, 30 Nov 2014 03:31:30 GMT',
// ctime: 'Sun, 30 Nov 2014 03:31:30 GMT',
// birthtime: 'Tue, 23 Sep 2014 01:13:26 GMT',
// compress: 'origin',
// contents:
// length: 4375,
// md5: '08f89d75eec2731ea6612ada474a1795' }
fileCache('index.js', 'gzip')(function (err, file) {
console.log(err, file)
// read file from cache, compress with gzip:
//
// { path: '/Users/zensh/git/toajs/file-cache/index.js',
// dir: '/Users/zensh/git/toajs/file-cache',
// name: 'index.js',
// ext: '.js',
// type: 'application/javascript',
// size: 4375,
// atime: 'Sun, 30 Nov 2014 03:48:47 GMT',
// mtime: 'Sun, 30 Nov 2014 03:48:35 GMT',
// ctime: 'Sun, 30 Nov 2014 03:48:35 GMT',
// birthtime: 'Tue, 23 Sep 2014 01:13:26 GMT',
// compress: 'gzip',
// contents:
// length: 2576,
// md5: '33a6f550613d64dc6b7e1e2d99d568bd' }
})
})
`
`bash`
npm install file-cache
`js`
const FileCache = require('file-cache')
const fileCache = FileCache('./static')
Return a read file function with cache.
#### options
Optional, Type: String or Object
options.root
Optional, Type: String, Default: process.cwd().
File directory, that allow to read file.
options.extraFiles
Optional, Type: Array, Default: [].
Extra files path, that allow to read.
options.compress
Optional, Type: Boolean, Default: true.
Allow to compress file with gzip or deflate
options.md5Encoding
Optional, Type: String, Default: base64.
The MD5 encoding can be 'hex', 'binary' or 'base64'.
options.maxCacheLength
Optional, Type: Number, Default: 0.
The maximum length of the files cache in bytes. if cache's size > maxCacheLength, then the least recently used file will be removed. if maxCacheLength === -1, cache will not be used. if maxCacheLength === 0, there is no limit.
options.minCompressLength
Optional, Type: Number, Default: 256.
The minimum length of the files size in bytes that could be compressed.
Return thunk function.
#### path
Required, Type: String
File path to read.
#### encodings
Optional, Type: String or Array
Compress encoding, ['gzip', 'deflate']`.
[npm-url]: https://npmjs.org/package/file-cache
[npm-image]: http://img.shields.io/npm/v/file-cache.svg
[travis-url]: https://travis-ci.org/thunks/file-cache
[travis-image]: http://img.shields.io/travis/thunks/file-cache.svg
[downloads-url]: https://npmjs.org/package/file-cache
[downloads-image]: http://img.shields.io/npm/dm/file-cache.svg?style=flat-square