file-entry-cache 5.0.0 → 5.0.1

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 +20 -5
  2. package/changelog.md +6 -0
  3. package/package.json +1 -1
package/cache.js CHANGED
@@ -229,6 +229,23 @@ module.exports = {
229
229
  normalizedEntries = { };
230
230
  cache.destroy();
231
231
  },
232
+
233
+ _getMetaForFileUsingCheckSum: function ( cacheEntry ) {
234
+ var contentBuffer = fs.readFileSync( cacheEntry.key );
235
+ var hash = this.getHash( contentBuffer );
236
+ var meta = Object.assign( cacheEntry.meta, { hash: hash } );
237
+ return meta;
238
+ },
239
+
240
+ _getMetaForFileUsingMtimeAndSize: function ( cacheEntry ) {
241
+ var stat = fs.statSync( cacheEntry.key );
242
+ var meta = Object.assign( cacheEntry.meta, {
243
+ size: stat.size,
244
+ mtime: stat.mtime.getTime()
245
+ } );
246
+ return meta;
247
+ },
248
+
232
249
  /**
233
250
  * Sync the files and persist them to the cache
234
251
  * @method reconcile
@@ -240,20 +257,18 @@ module.exports = {
240
257
 
241
258
  var entries = normalizedEntries;
242
259
  var keys = Object.keys( entries );
243
- var me = this;
244
260
 
245
261
  if ( keys.length === 0 ) {
246
262
  return;
247
263
  }
248
264
 
265
+ var me = this;
266
+
249
267
  keys.forEach( function ( entryName ) {
250
268
  var cacheEntry = entries[ entryName ];
251
269
 
252
270
  try {
253
- var contentBuffer = fs.readFileSync( cacheEntry.key );
254
- var hash = me.getHash( contentBuffer );
255
- var meta = Object.assign( cacheEntry.meta, { hash: hash } );
256
-
271
+ var meta = useChecksum ? me._getMetaForFileUsingCheckSum( cacheEntry ) : me._getMetaForFileUsingMtimeAndSize( cacheEntry );
257
272
  cache.setKey( entryName, meta );
258
273
  } catch (err) {
259
274
  // if the file does not exists we don't save it
package/changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
 
2
2
  # file-entry-cache - Changelog
3
+ ## v5.0.1
4
+ - **Bug Fixes**
5
+ - Fix missing checksum comparison from reconcile since now we use mtime and size by default. - [e858aa9]( https://github.com/royriojas/file-entry-cache/commit/e858aa9 ), [Roy Riojas](https://github.com/Roy Riojas), 04/02/2019 12:30:22
6
+
7
+ Old mode using checkSum can still be used by passing the `useCheckSum` parameter to the `create` or `createFromFile` methods.
8
+
3
9
  ## v5.0.0
4
10
  - **Refactoring**
5
11
  - Make checksum comparison optional - [b0f9ae0]( https://github.com/royriojas/file-entry-cache/commit/b0f9ae0 ), [Roy Riojas](https://github.com/Roy Riojas), 03/02/2019 21:17:39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-entry-cache",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
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",