aboutsummaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/util
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2019-10-06 21:37:45 +0200
commit3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch)
treec7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/fs-extra/lib/util
parent412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff)
downloadwebsite-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz
website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip
build: Add some required modules for node
Diffstat (limited to 'node_modules/fs-extra/lib/util')
-rw-r--r--node_modules/fs-extra/lib/util/assign.js16
-rw-r--r--node_modules/fs-extra/lib/util/buffer.js11
-rw-r--r--node_modules/fs-extra/lib/util/utimes.js79
3 files changed, 106 insertions, 0 deletions
diff --git a/node_modules/fs-extra/lib/util/assign.js b/node_modules/fs-extra/lib/util/assign.js
new file mode 100644
index 0000000..317e5ec
--- /dev/null
+++ b/node_modules/fs-extra/lib/util/assign.js
@@ -0,0 +1,16 @@
+'use strict'
+
+// simple mutable assign
+function assign () {
+ const args = [].slice.call(arguments).filter(i => i)
+ const dest = args.shift()
+ args.forEach(src => {
+ Object.keys(src).forEach(key => {
+ dest[key] = src[key]
+ })
+ })
+
+ return dest
+}
+
+module.exports = assign
diff --git a/node_modules/fs-extra/lib/util/buffer.js b/node_modules/fs-extra/lib/util/buffer.js
new file mode 100644
index 0000000..93af51b
--- /dev/null
+++ b/node_modules/fs-extra/lib/util/buffer.js
@@ -0,0 +1,11 @@
+/* eslint-disable node/no-deprecated-api */
+module.exports = function (size) {
+ if (typeof Buffer.allocUnsafe === 'function') {
+ try {
+ return Buffer.allocUnsafe(size)
+ } catch (e) {
+ return new Buffer(size)
+ }
+ }
+ return new Buffer(size)
+}
diff --git a/node_modules/fs-extra/lib/util/utimes.js b/node_modules/fs-extra/lib/util/utimes.js
new file mode 100644
index 0000000..8916a1b
--- /dev/null
+++ b/node_modules/fs-extra/lib/util/utimes.js
@@ -0,0 +1,79 @@
+'use strict'
+
+const fs = require('graceful-fs')
+const os = require('os')
+const path = require('path')
+
+// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
+function hasMillisResSync () {
+ let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
+ tmpfile = path.join(os.tmpdir(), tmpfile)
+
+ // 550 millis past UNIX epoch
+ const d = new Date(1435410243862)
+ fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
+ const fd = fs.openSync(tmpfile, 'r+')
+ fs.futimesSync(fd, d, d)
+ fs.closeSync(fd)
+ return fs.statSync(tmpfile).mtime > 1435410243000
+}
+
+function hasMillisRes (callback) {
+ let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
+ tmpfile = path.join(os.tmpdir(), tmpfile)
+
+ // 550 millis past UNIX epoch
+ const d = new Date(1435410243862)
+ fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
+ if (err) return callback(err)
+ fs.open(tmpfile, 'r+', (err, fd) => {
+ if (err) return callback(err)
+ fs.futimes(fd, d, d, err => {
+ if (err) return callback(err)
+ fs.close(fd, err => {
+ if (err) return callback(err)
+ fs.stat(tmpfile, (err, stats) => {
+ if (err) return callback(err)
+ callback(null, stats.mtime > 1435410243000)
+ })
+ })
+ })
+ })
+ })
+}
+
+function timeRemoveMillis (timestamp) {
+ if (typeof timestamp === 'number') {
+ return Math.floor(timestamp / 1000) * 1000
+ } else if (timestamp instanceof Date) {
+ return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
+ } else {
+ throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
+ }
+}
+
+function utimesMillis (path, atime, mtime, callback) {
+ // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
+ fs.open(path, 'r+', (err, fd) => {
+ if (err) return callback(err)
+ fs.futimes(fd, atime, mtime, futimesErr => {
+ fs.close(fd, closeErr => {
+ if (callback) callback(futimesErr || closeErr)
+ })
+ })
+ })
+}
+
+function utimesMillisSync (path, atime, mtime) {
+ const fd = fs.openSync(path, 'r+')
+ fs.futimesSync(fd, atime, mtime)
+ return fs.closeSync(fd)
+}
+
+module.exports = {
+ hasMillisRes,
+ hasMillisResSync,
+ timeRemoveMillis,
+ utimesMillis,
+ utimesMillisSync
+}