@seald-io/nedb
Advanced tools
Comparing version 2.1.0-2 to 2.1.0-3
@@ -75,2 +75,30 @@ /** | ||
/** | ||
* Fully write or rewrite the datafile | ||
* @param {String} filename | ||
* @param {String[]} lines | ||
* @param {Function} callback | ||
*/ | ||
storage.writeFileLines = (filename, lines, callback = () => {}) => { | ||
try { | ||
const stream = fs.createWriteStream(filename) | ||
const readable = Readable.from(lines) | ||
readable.on('data', (line) => { | ||
try { | ||
stream.write(line) | ||
stream.write('\n') | ||
} catch (err) { | ||
callback(err) | ||
} | ||
}) | ||
readable.on('end', () => { | ||
stream.close(callback) | ||
}) | ||
readable.on('error', callback) | ||
stream.on('error', callback) | ||
} catch (err) { | ||
callback(err) | ||
} | ||
} | ||
/** | ||
* Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost) | ||
@@ -93,21 +121,3 @@ * @param {String} filename | ||
cb => { | ||
try { | ||
const stream = fs.createWriteStream(tempFilename) | ||
const readable = Readable.from(lines) | ||
readable.on('data', (line) => { | ||
try { | ||
stream.write(line) | ||
stream.write('\n') | ||
} catch (err) { | ||
cb(err) | ||
} | ||
}) | ||
readable.on('end', () => { | ||
stream.close(cb) | ||
}) | ||
readable.on('error', cb) | ||
stream.on('error', cb) | ||
} catch (err) { | ||
cb(err) | ||
} | ||
storage.writeFileLines(tempFilename, lines, cb) | ||
}, | ||
@@ -114,0 +124,0 @@ async.apply(storage.flushToStorage, tempFilename), |
{ | ||
"name": "@seald-io/nedb", | ||
"version": "2.1.0-2", | ||
"version": "2.1.0-3", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "lib/**/*.js", |
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
509702
9889