Socket
Socket
Sign inDemoInstall

tough-cookie-file-store

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tough-cookie-file-store - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

60

lib/file-store.js

@@ -174,8 +174,62 @@ 'use strict';

function saveToFile(filePath, data, cb) {
FileCookieStore.prototype.getAllCookies = function(cb) {
var cookies = [];
var idx = this.idx;
var domains = Object.keys(idx);
domains.forEach(function(domain) {
var paths = Object.keys(idx[domain]);
paths.forEach(function(path) {
var keys = Object.keys(idx[domain][path]);
keys.forEach(function(key) {
if (key !== null) {
cookies.push(idx[domain][path][key]);
}
});
});
});
// Sort by creationIndex so deserializing retains the creation order.
// When implementing your own store, this SHOULD retain the order too
cookies.sort(function(a,b) {
return (a.creationIndex||0) - (b.creationIndex||0);
});
cb(null, cookies);
};
// Avoid parallel writes to the same file
var _writing_ = {};
function writeFile(filePath, data, done) {
var dataJson = JSON.stringify(data);
fs.writeFileSync(filePath, dataJson);
cb();
var wo = { done: done, next: [] };
_writing_[filePath] = wo;
fs.writeFile(filePath, dataJson, function (err) {
// If we have new pending writes, execute them now
if ( wo.next.length ) {
writeFile(filePath, wo.data, wo.next);
}
else {
delete _writing_[filePath];
}
if (err) throw err;
wo.done.forEach(function(cb) {
cb();
});
});
}
function saveToFile(filePath, data, cb) {
var wo = _writing_[filePath];
// If not writing to this file, start writing right now
if ( !wo ) {
writeFile(filePath, data, [cb]);
}
// If writing in process, add to pending
else {
wo.data = data;
wo.next.push(cb);
}
}
function loadFromFile(filePath, cb) {

@@ -182,0 +236,0 @@ if (fs.existsSync(filePath)) {

8

package.json
{
"name": "tough-cookie-file-store",
"description": "Another file store for tough-cookie module",
"version": "1.1.1",
"version": "1.2.0",
"author": "Ivan Marban",

@@ -19,6 +19,6 @@ "homepage": "https://github.com/ivanmarban/tough-cookie-file-store",

"file",
"store"
"store"
],
"dependencies": {
"tough-cookie": "^2.3.1"
"tough-cookie": "^2.3.3"
},

@@ -30,2 +30,2 @@ "main": "index",

"license": "MIT"
}
}

@@ -24,3 +24,3 @@ # tough-cookie-file-store

cookieInstance.isExpired() // will return True if the cookie is expired
cookieInstance.isEmpty() // will return True is cookie is empty
cookieInstance.isEmpty() // will return True if cookie is empty

@@ -27,0 +27,0 @@ /* request example */

Sorry, the diff of this file is not supported yet

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