Open nylen opened 10 years ago
This also means that there's not a reliable way to tell when tough-cookie-filestore
has finished writing the JSON file. Since most people will probably be using this library from request
, which only supports synchronous operations, I'd recommend just using fs.writeFileSync
instead.
:+1: for this I just met the same problem The json file became a mess
undefined:1
895Z","hostOnly":false,"lastAccessed":"2015-01-22T13:44:01.895Z"}}}}94Z"},"pt4
^
SyntaxError: Unexpected number
at Object.parse (native)
at loadFromFile (/home/fritx/dev/qq/node_modules/tough-cookie-filestore/lib/filestore.js:150:32)
at new FileCookieStore (/home/fritx/dev/qq/node_modules/tough-cookie-filestore/lib/filestore.js:14:5)
And I simply tried fs.writeFileSync
instead inside saveToFile
then it works
+1
Hey @sarkian, we at @request would like to use your fork of tough-cookie-filestore
instead. Open an issue and ping me and @simov on it.
Here's some more context: https://github.com/request/request/pull/1192
The
saveToFile
method calls the async version offs.writeFile
, so it's possible that this method will be called multiple times concurrently. This would either corrupt the JSON file, or fail with an error - I'm not sure which.