summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/write-file-atomic
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/write-file-atomic')
-rw-r--r--deps/npm/node_modules/write-file-atomic/README.md3
-rw-r--r--deps/npm/node_modules/write-file-atomic/index.js46
-rw-r--r--deps/npm/node_modules/write-file-atomic/package.json81
3 files changed, 64 insertions, 66 deletions
diff --git a/deps/npm/node_modules/write-file-atomic/README.md b/deps/npm/node_modules/write-file-atomic/README.md
index a9d3461db1..63f00420ca 100644
--- a/deps/npm/node_modules/write-file-atomic/README.md
+++ b/deps/npm/node_modules/write-file-atomic/README.md
@@ -13,6 +13,7 @@ atomic and allows you set ownership (uid/gid of the file).
* uid **Number**
* gid **Number**
* encoding **String** | **Null** default = 'utf8'
+ * fsync **Boolean** default = true
* mode **Number** default = 438 (aka 0666 in Octal)
callback **Function**
@@ -30,6 +31,8 @@ you'll get an error.
The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
+If the **fsync** option is **false**, writeFile will skip the final fsync call.
+
Example:
```javascript
diff --git a/deps/npm/node_modules/write-file-atomic/index.js b/deps/npm/node_modules/write-file-atomic/index.js
index 7939828e53..c677ee9622 100644
--- a/deps/npm/node_modules/write-file-atomic/index.js
+++ b/deps/npm/node_modules/write-file-atomic/index.js
@@ -6,7 +6,6 @@ module.exports._getTmpname = getTmpname // for testing
var fs = require('graceful-fs')
var chain = require('slide').chain
var MurmurHash3 = require('imurmurhash')
-var extend = Object.assign || require('util')._extend
var invocations = 0
function getTmpname (filename) {
@@ -38,7 +37,7 @@ function _writeFile (filename, data, options, callback) {
return fs.stat(filename, function (err, stats) {
if (err || !stats) return thenWriteFile()
- options = extend({}, options)
+ options = Object.assign({}, options)
if (!options.mode) {
options.mode = stats.mode
}
@@ -51,15 +50,41 @@ function _writeFile (filename, data, options, callback) {
function thenWriteFile () {
chain([
- [fs, fs.writeFile, tmpfile, data, options.encoding || 'utf8'],
- options.mode && [fs, fs.chmod, tmpfile, options.mode],
+ [writeFileAsync, tmpfile, data, options.mode, options.encoding || 'utf8'],
options.chown && [fs, fs.chown, tmpfile, options.chown.uid, options.chown.gid],
+ options.mode && [fs, fs.chmod, tmpfile, options.mode],
[fs, fs.rename, tmpfile, filename]
], function (err) {
err ? fs.unlink(tmpfile, function () { callback(err) })
: callback()
})
}
+
+ // doing this instead of `fs.writeFile` in order to get the ability to
+ // call `fsync`.
+ function writeFileAsync (file, data, mode, encoding, cb) {
+ fs.open(file, 'w', options.mode, function (err, fd) {
+ if (err) return cb(err)
+ if (Buffer.isBuffer(data)) {
+ return fs.write(fd, data, 0, data.length, 0, syncAndClose)
+ } else if (data != null) {
+ return fs.write(fd, String(data), 0, String(encoding), syncAndClose)
+ } else {
+ return syncAndClose()
+ }
+ function syncAndClose (err) {
+ if (err) return cb(err)
+ if (options.fsync !== false) {
+ fs.fsync(fd, function (err) {
+ if (err) return cb(err)
+ fs.close(fd, cb)
+ })
+ } else {
+ fs.close(fd, cb)
+ }
+ }
+ })
+ }
}
function writeFileSync (filename, data, options) {
@@ -77,7 +102,7 @@ function writeFileSync (filename, data, options) {
// Default behavior is to copy it from original file
try {
var stats = fs.statSync(filename)
- options = extend({}, options)
+ options = Object.assign({}, options)
if (!options.mode) {
options.mode = stats.mode
}
@@ -89,7 +114,16 @@ function writeFileSync (filename, data, options) {
}
}
- fs.writeFileSync(tmpfile, data, options.encoding || 'utf8')
+ var fd = fs.openSync(tmpfile, 'w', options.mode)
+ if (Buffer.isBuffer(data)) {
+ fs.writeSync(fd, data, 0, data.length, 0)
+ } else if (data != null) {
+ fs.writeSync(fd, String(data), 0, String(options.encoding || 'utf8'))
+ }
+ if (options.fsync !== false) {
+ fs.fsyncSync(fd)
+ }
+ fs.closeSync(fd)
if (options.chown) fs.chownSync(tmpfile, options.chown.uid, options.chown.gid)
if (options.mode) fs.chmodSync(tmpfile, options.mode)
fs.renameSync(tmpfile, filename)
diff --git a/deps/npm/node_modules/write-file-atomic/package.json b/deps/npm/node_modules/write-file-atomic/package.json
index 2b1db0d603..9f8043b094 100644
--- a/deps/npm/node_modules/write-file-atomic/package.json
+++ b/deps/npm/node_modules/write-file-atomic/package.json
@@ -1,51 +1,28 @@
{
- "_args": [
- [
- {
- "raw": "write-file-atomic@1.3.1",
- "scope": null,
- "escapedName": "write-file-atomic",
- "name": "write-file-atomic",
- "rawSpec": "1.3.1",
- "spec": "1.3.1",
- "type": "version"
- },
- "/Users/rebecca/code/npm"
- ]
- ],
- "_from": "write-file-atomic@1.3.1",
- "_id": "write-file-atomic@1.3.1",
- "_inCache": true,
+ "_from": "write-file-atomic@latest",
+ "_id": "write-file-atomic@2.1.0",
+ "_inBundle": false,
+ "_integrity": "sha512-0TZ20a+xcIl4u0+Mj5xDH2yOWdmQiXlKf9Hm+TgDXjTMsEYb+gDrmb8e8UNAzMCitX8NBqG4Z/FUQIyzv/R1JQ==",
"_location": "/write-file-atomic",
- "_nodeVersion": "7.3.0",
- "_npmOperationalInternal": {
- "host": "packages-18-east.internal.npmjs.com",
- "tmp": "tmp/write-file-atomic-1.3.1.tgz_1483776142964_0.11427561868913472"
- },
- "_npmUser": {
- "name": "iarna",
- "email": "me@re-becca.org"
- },
- "_npmVersion": "4.1.1",
"_phantomChildren": {},
"_requested": {
- "raw": "write-file-atomic@1.3.1",
- "scope": null,
- "escapedName": "write-file-atomic",
+ "type": "tag",
+ "registry": true,
+ "raw": "write-file-atomic@latest",
"name": "write-file-atomic",
- "rawSpec": "1.3.1",
- "spec": "1.3.1",
- "type": "version"
+ "escapedName": "write-file-atomic",
+ "rawSpec": "latest",
+ "saveSpec": null,
+ "fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
- "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.1.tgz",
- "_shasum": "7d45ba32316328dd1ec7d90f60ebc0d845bb759a",
- "_shrinkwrap": null,
- "_spec": "write-file-atomic@1.3.1",
- "_where": "/Users/rebecca/code/npm",
+ "_resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.1.0.tgz",
+ "_shasum": "1769f4b551eedce419f0505deae2e26763542d37",
+ "_spec": "write-file-atomic@latest",
+ "_where": "/Users/zkat/Documents/code/npm",
"author": {
"name": "Rebecca Turner",
"email": "me@re-becca.org",
@@ -54,28 +31,24 @@
"bugs": {
"url": "https://github.com/iarna/write-file-atomic/issues"
},
+ "bundleDependencies": false,
"dependencies": {
"graceful-fs": "^4.1.11",
"imurmurhash": "^0.1.4",
"slide": "^1.1.5"
},
+ "deprecated": false,
"description": "Write files in an atomic fashion w/configurable ownership",
"devDependencies": {
"mkdirp": "^0.5.1",
"require-inject": "^1.4.0",
"rimraf": "^2.5.4",
- "standard": "^5.4.1",
- "tap": "^2.3.1"
- },
- "directories": {},
- "dist": {
- "shasum": "7d45ba32316328dd1ec7d90f60ebc0d845bb759a",
- "tarball": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-1.3.1.tgz"
+ "standard": "^10.0.2",
+ "tap": "^10.3.2"
},
"files": [
"index.js"
],
- "gitHead": "56fef5763513905d7e43aa685adad80002445474",
"homepage": "https://github.com/iarna/write-file-atomic",
"keywords": [
"writeFile",
@@ -83,25 +56,13 @@
],
"license": "ISC",
"main": "index.js",
- "maintainers": [
- {
- "name": "iarna",
- "email": "me@re-becca.org"
- },
- {
- "name": "othiym23",
- "email": "ogd@aoaioxxysz.net"
- }
- ],
"name": "write-file-atomic",
- "optionalDependencies": {},
- "readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/iarna/write-file-atomic.git"
},
"scripts": {
- "test": "standard && tap --coverage test/*.js"
+ "test": "standard && tap --100 test/*.js"
},
- "version": "1.3.1"
+ "version": "2.1.0"
}