Socket
Socket
Sign inDemoInstall

sync-disk-cache

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sync-disk-cache - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

60

index.js

@@ -9,6 +9,7 @@ 'use strict';

var rimraf = require('rimraf').sync;
var unlink = fs.unlink;
var unlink = fs.unlinkSync;
var chmod = fs.chmodSync;
var tmpDir = require('os').tmpDir();
var debug = require('debug')('sync-disk-cache');
var zlib = require('zlib');

@@ -20,3 +21,2 @@ var mode = {

var CacheEntry = require('./lib/cache-entry');
/*

@@ -53,2 +53,18 @@ * @private

var COMPRESSIONS = {
deflate: {
in: zlib.deflateSync,
out: zlib.inflateSync,
},
deflateRaw: {
in: zlib.deflateRawSync,
out: zlib.inflateRawSync,
},
gzip: {
in: zlib.gzipSync,
out: zlib.gunzipSync,
},
};
/*

@@ -58,11 +74,13 @@ *

* @param {String} key the global key that represents this cache in its final location
* @param {String} location an optional string path to the location for the
* @param {String} options optional string path to the location for the
* cache. If omitted the system tmpdir is used
*/
function Cache(key, location) {
this.tmpDir = location|| tmpDir;
function Cache(key, _) {
var options = _ || {};
this.tmpDir = options.location|| tmpDir;
this.compression = options.compression;
this.key = key || 'default-disk-cache';
this.root = path.join(this.tmpDir, this.key);
debug('new Cache { root: %s }', this.root);
debug('new Cache { root: %s, compression: %s }', this.root, this.compression);
}

@@ -113,3 +131,3 @@

try {
return processFile(filePath, readFile(filePath));
return processFile(filePath, this.decompress(readFile(filePath)));
} catch(e) {

@@ -134,3 +152,3 @@ return handleENOENT(e);

mkdirp(path.dirname(filePath), mode);
writeFile(filePath, value, mode);
writeFile(filePath, this.compress(value), mode);
chmod(filePath, mode.mode);

@@ -166,4 +184,2 @@

* @returns the path where the key's value may reside
*
*
*/

@@ -174,2 +190,26 @@ Cache.prototype.pathFor = function(key) {

/*
* @public
*
* @method decompress
* @param {String} compressedValue
* @returns decompressedValue
*/
Cache.prototype.decompress = function(value) {
if (!this.compression) { return value; }
return COMPRESSIONS[this.compression].out(value);
};
/*
* @public
*
* @method compress
* @param {String} value
* @returns compressedValue
*/
Cache.prototype.compress = function(value) {
if (!this.compression) { return value; }
return COMPRESSIONS[this.compression].in(value);
};
module.exports = Cache;

2

package.json
{
"name": "sync-disk-cache",
"version": "0.0.2",
"version": "1.0.0",
"description": "sync disk cache",

@@ -5,0 +5,0 @@ "files": [

@@ -40,4 +40,14 @@ # sync-disk-cache [![Build status](https://ci.appveyor.com/api/projects/status/lfliompah66m611x?svg=true)](https://ci.appveyor.com/project/embercli/sync-disk-cache)

Enable compression:
```js
var Cache = require('sync-disk-cache');
var cache = new Cache('my-cache', {
compression: 'gzip' | 'deflate' | 'deflateRaw' // basically just what nodes zlib's ships with
})
```
## License
Licensed under the MIT License, Copyright 2015 Stefan Penner
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc