Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (data) {
try {
var dataJson = JSON.parse(data);
} catch (e) {
throw new Error('Could not parse cookie file ' + filePath + '. Please ensure it is not corrupted.');
}
} else {
var dataJson = null;
}
for (var domainName in dataJson) {
for (var pathName in dataJson[domainName]) {
for (var cookieName in dataJson[domainName][pathName]) {
dataJson[domainName][pathName][cookieName] = tough.fromJSON(JSON.stringify(dataJson[domainName][pathName][cookieName]));
}
}
}
cb(dataJson);
}
dataJson;
try {
data = fs.readFileSync(this.filePath);
dataJson = data ? JSON.parse(data) : null;
} catch(e) {
return {};
}
for (let domain in dataJson) {
for (let path in dataJson[domain]) {
for (let key in dataJson[domain][path]) {
dataJson[domain][path][key] = tough.fromJSON(JSON.stringify(dataJson[domain][path][key]));
}
}
}
return dataJson;
}
FileCookieStore.prototype.loadFromFile = function (filePath, option, cb) {
var data = fs.readFileSync(filePath, { encoding: 'utf8', flag: 'a+' });
if (option.encrypt && data) {
var decipher = crypto.createDecipher(option.algorithm || '', option.password || '');
data = decipher.update(data, 'hex', 'utf8');
data += decipher.final('utf8');
}
var dataJson = data ? JSON.parse(data) : null;
for (var domainName in dataJson) {
for (var pathName in dataJson[domainName]) {
for (var cookieName in dataJson[domainName][pathName]) {
dataJson[domainName][pathName][cookieName] = tough.fromJSON(JSON.stringify(dataJson[domainName][pathName][cookieName]));
}
}
}
cb(dataJson);
};
return FileCookieStore;