file-entry-cache 2.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cache.js +26 -14
  2. package/changelog.md +47 -0
  3. package/package.json +7 -7
package/cache.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var path = require( 'path' );
2
+ var crypto = require( 'crypto' );
2
3
 
3
4
  module.exports = {
4
5
  createFromFile: function ( filePath ) {
@@ -11,7 +12,6 @@ module.exports = {
11
12
  var fs = require( 'fs' );
12
13
  var flatCache = require( 'flat-cache' );
13
14
  var cache = flatCache.load( cacheId, _path );
14
- var assign = require( 'object-assign' );
15
15
  var normalizedEntries = { };
16
16
 
17
17
  var removeNotFoundFiles = function removeNotFoundFiles() {
@@ -36,6 +36,20 @@ module.exports = {
36
36
  * @type {Object}
37
37
  */
38
38
  cache: cache,
39
+
40
+ /**
41
+ * Given a buffer, calculate md5 hash of its content.
42
+ * @method getHash
43
+ * @param {Buffer} buffer buffer to calculate hash on
44
+ * @return {String} content hash digest
45
+ */
46
+ getHash: function ( buffer ) {
47
+ return crypto
48
+ .createHash( 'md5' )
49
+ .update( buffer )
50
+ .digest( 'hex' );
51
+ },
52
+
39
53
  /**
40
54
  * Return whether or not a file has changed since last time reconcile was called.
41
55
  * @method hasFileChanged
@@ -82,29 +96,28 @@ module.exports = {
82
96
  getFileDescriptor: function ( file ) {
83
97
  var meta = cache.getKey( file );
84
98
  var cacheExists = !!meta;
85
- var fstat;
86
99
  var me = this;
100
+ var contentBuffer;
87
101
 
88
102
  try {
89
- fstat = fs.statSync( file );
103
+ contentBuffer = fs.readFileSync( file );
90
104
  } catch (ex) {
91
105
  me.removeEntry( file );
92
106
  return { key: file, notFound: true, err: ex };
93
107
  }
94
108
 
95
- var cSize = fstat.size;
96
- var cTime = fstat.mtime.getTime();
109
+ var isDifferent = true;
110
+ var hash = this.getHash( contentBuffer );
97
111
 
98
112
  if ( !meta ) {
99
- meta = { size: cSize, mtime: cTime };
113
+ meta = { hash: hash };
100
114
  } else {
101
- var isDifferentDate = cTime !== meta.mtime;
102
- var isDifferentSize = cSize !== meta.size;
115
+ isDifferent = hash !== meta.hash;
103
116
  }
104
117
 
105
118
  var nEntry = normalizedEntries[ file ] = {
106
119
  key: file,
107
- changed: !cacheExists || isDifferentDate || isDifferentSize,
120
+ changed: !cacheExists || isDifferent,
108
121
  meta: meta
109
122
  };
110
123
 
@@ -184,6 +197,7 @@ module.exports = {
184
197
 
185
198
  var entries = normalizedEntries;
186
199
  var keys = Object.keys( entries );
200
+ var me = this;
187
201
 
188
202
  if ( keys.length === 0 ) {
189
203
  return;
@@ -193,11 +207,9 @@ module.exports = {
193
207
  var cacheEntry = entries[ entryName ];
194
208
 
195
209
  try {
196
- var stat = fs.statSync( cacheEntry.key );
197
- var meta = assign( cacheEntry.meta, {
198
- size: stat.size,
199
- mtime: stat.mtime.getTime()
200
- } );
210
+ var contentBuffer = fs.readFileSync( cacheEntry.key );
211
+ var hash = me.getHash( contentBuffer );
212
+ var meta = Object.assign( cacheEntry.meta, { hash: hash } );
201
213
 
202
214
  cache.setKey( entryName, meta );
203
215
  } catch (err) {
package/changelog.md CHANGED
@@ -1,5 +1,52 @@
1
1
 
2
2
  # file-entry-cache - Changelog
3
+ ## v4.0.0
4
+ - **Build Scripts Changes**
5
+ - use the same node versions eslint use - [563cfee]( https://github.com/royriojas/file-entry-cache/commit/563cfee ), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 23:29:34
6
+
7
+
8
+ - **Other changes**
9
+ - Remove object-assign dependency. - [d0f598e]( https://github.com/royriojas/file-entry-cache/commit/d0f598e ), [Corey Farrell](https://github.com/Corey Farrell), 08/01/2019 23:09:51
10
+
11
+ node.js >=4 is required so object-assign is no longer needed, the native
12
+ Object.assign can be used instead.
13
+
14
+ ## v3.0.0
15
+ - **Build Scripts Changes**
16
+ - Upgrade flat-cache dep to latest - [078b0df]( https://github.com/royriojas/file-entry-cache/commit/078b0df ), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 21:54:40
17
+
18
+
19
+ - Commit new package-lock.json file - [245fe62]( https://github.com/royriojas/file-entry-cache/commit/245fe62 ), [Roy Riojas](https://github.com/Roy Riojas), 08/01/2019 20:56:21
20
+
21
+
22
+ - **Refactoring**
23
+ - add eslintrc file - [6dd32d8]( https://github.com/royriojas/file-entry-cache/commit/6dd32d8 ), [Roy Riojas](https://github.com/Roy Riojas), 22/08/2018 11:58:17
24
+
25
+
26
+ - **Other changes**
27
+ - Move variable definition out of else block - [ea05441]( https://github.com/royriojas/file-entry-cache/commit/ea05441 ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 25/04/2017 13:19:00
28
+
29
+
30
+ - Add script and cmd to test hash/checksum performance - [7f60e0a]( https://github.com/royriojas/file-entry-cache/commit/7f60e0a ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 24/04/2017 16:43:12
31
+
32
+
33
+ - Calculate md5 hexdigest instead of Adler-32 checksum - [f9e5c69]( https://github.com/royriojas/file-entry-cache/commit/f9e5c69 ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 24/04/2017 16:43:12
34
+
35
+
36
+ - How to reproduce - [4edc2dc]( https://github.com/royriojas/file-entry-cache/commit/4edc2dc ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 24/04/2017 15:49:32
37
+
38
+
39
+ - Test handling of removed files - [09d9ec5]( https://github.com/royriojas/file-entry-cache/commit/09d9ec5 ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 19/04/2017 21:51:50
40
+
41
+
42
+ - Use content checksum instead of mtime and fsize - [343b340]( https://github.com/royriojas/file-entry-cache/commit/343b340 ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 19/04/2017 21:51:47
43
+
44
+
45
+ - **Revert**
46
+ - Revert "How to reproduce" - [4b4e54a]( https://github.com/royriojas/file-entry-cache/commit/4b4e54a ), [Zakhar Shapurau](https://github.com/Zakhar Shapurau), 25/04/2017 13:15:36
47
+
48
+ This reverts commit 4edc2dcec01574247bfc2e0a2fe26527332b7df3.
49
+
3
50
  ## v2.0.0
4
51
  - **Features**
5
52
  - do not persist and prune removed files from cache. Relates to [#2](https://github.com/royriojas/file-entry-cache/issues/2) - [408374d]( https://github.com/royriojas/file-entry-cache/commit/408374d ), [Roy Riojas](https://github.com/Roy Riojas), 16/08/2016 15:47:58
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-entry-cache",
3
- "version": "2.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Super simple cache for file metadata, useful for process that work o a given series of files and that only need to repeat the job on the changed ones since the previous run of the process",
5
5
  "repository": "royriojas/file-entry-cache",
6
6
  "license": "MIT",
@@ -13,12 +13,12 @@
13
13
  "cache.js"
14
14
  ],
15
15
  "engines": {
16
- "node": ">=0.10.0"
16
+ "node": ">=4"
17
17
  },
18
18
  "scripts": {
19
- "beautify": "esbeautifier 'cache.js' 'test/**/*.js'",
19
+ "beautify": "esbeautifier 'cache.js' 'test/**/*.js' 'perf.js'",
20
20
  "beautify-check": "npm run beautify -- -k",
21
- "eslint": "eslinter 'cache.js' 'specs/**/*.js'",
21
+ "eslint": "eslinter 'cache.js' 'specs/**/*.js' 'perf.js'",
22
22
  "lint": "npm run beautify && npm run eslint",
23
23
  "verify": "npm run beautify-check && npm run eslint",
24
24
  "install-hooks": "prepush install && changelogx install-hook && precommit install",
@@ -30,6 +30,7 @@
30
30
  "bump-minor": "npm run pre-v && npm version minor -m 'BLD: Release v%s' && npm run post-v",
31
31
  "bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v",
32
32
  "test": "npm run verify --silent && mocha -R spec test/specs",
33
+ "perf": "node perf.js",
33
34
  "cover": "istanbul cover test/runner.js html text-summary",
34
35
  "watch": "watch-run -i -p 'test/specs/**/*.js' istanbul cover test/runner.js html text-summary"
35
36
  },
@@ -61,7 +62,7 @@
61
62
  },
62
63
  "devDependencies": {
63
64
  "chai": "^3.2.0",
64
- "changelogx": "^1.0.18",
65
+ "changelogx": "3.0.0",
65
66
  "commander": "^2.6.0",
66
67
  "del": "^2.0.2",
67
68
  "esbeautifier": "^4.2.11",
@@ -78,7 +79,6 @@
78
79
  "write": "^0.3.1"
79
80
  },
80
81
  "dependencies": {
81
- "flat-cache": "^1.2.1",
82
- "object-assign": "^4.0.1"
82
+ "flat-cache": "^2.0.1"
83
83
  }
84
84
  }