tough-cookie-file-store
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -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)) { |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11425
241
5
Updatedtough-cookie@^2.3.3