UrgentcareCLI 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/UrgentCare/CLI.rb +1 -2
- data/lib/UrgentCare/Scraper.rb +65 -0
- data/lib/UrgentCare/version.rb +2 -2
- data/lib/UrgentCare.rb +1 -0
- metadata +3 -313
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -5
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -84
- data/LICENSE.txt +0 -21
- data/Notes +0 -41
- data/README.md +0 -41
- data/Rakefile +0 -8
- data/UrgentCare.gemspec +0 -39
- data/background.jpg +0 -0
- data/data.txt +0 -4
- data/lib/Urgentcare/Scraper.rb +0 -78
- data/node_modules/.bin/rimraf +0 -1
- data/node_modules/.package-lock.json +0 -250
- data/node_modules/balanced-match/.github/FUNDING.yml +0 -2
- data/node_modules/balanced-match/LICENSE.md +0 -21
- data/node_modules/balanced-match/README.md +0 -97
- data/node_modules/balanced-match/index.js +0 -62
- data/node_modules/balanced-match/package.json +0 -48
- data/node_modules/brace-expansion/LICENSE +0 -21
- data/node_modules/brace-expansion/README.md +0 -129
- data/node_modules/brace-expansion/index.js +0 -201
- data/node_modules/brace-expansion/package.json +0 -47
- data/node_modules/concat-map/.travis.yml +0 -4
- data/node_modules/concat-map/LICENSE +0 -18
- data/node_modules/concat-map/README.markdown +0 -62
- data/node_modules/concat-map/example/map.js +0 -6
- data/node_modules/concat-map/index.js +0 -13
- data/node_modules/concat-map/package.json +0 -43
- data/node_modules/concat-map/test/map.js +0 -39
- data/node_modules/core-util-is/LICENSE +0 -19
- data/node_modules/core-util-is/README.md +0 -3
- data/node_modules/core-util-is/float.patch +0 -604
- data/node_modules/core-util-is/lib/util.js +0 -107
- data/node_modules/core-util-is/package.json +0 -32
- data/node_modules/core-util-is/test.js +0 -68
- data/node_modules/fs.realpath/LICENSE +0 -43
- data/node_modules/fs.realpath/README.md +0 -33
- data/node_modules/fs.realpath/index.js +0 -66
- data/node_modules/fs.realpath/old.js +0 -303
- data/node_modules/fs.realpath/package.json +0 -26
- data/node_modules/glob/LICENSE +0 -21
- data/node_modules/glob/README.md +0 -375
- data/node_modules/glob/changelog.md +0 -67
- data/node_modules/glob/common.js +0 -234
- data/node_modules/glob/glob.js +0 -788
- data/node_modules/glob/package.json +0 -51
- data/node_modules/glob/sync.js +0 -484
- data/node_modules/immediate/LICENSE.txt +0 -20
- data/node_modules/immediate/README.md +0 -93
- data/node_modules/immediate/dist/immediate.js +0 -75
- data/node_modules/immediate/dist/immediate.min.js +0 -1
- data/node_modules/immediate/lib/browser.js +0 -69
- data/node_modules/immediate/lib/index.js +0 -73
- data/node_modules/immediate/package.json +0 -42
- data/node_modules/inflight/LICENSE +0 -15
- data/node_modules/inflight/README.md +0 -37
- data/node_modules/inflight/inflight.js +0 -54
- data/node_modules/inflight/package.json +0 -29
- data/node_modules/inherits/LICENSE +0 -16
- data/node_modules/inherits/README.md +0 -42
- data/node_modules/inherits/inherits.js +0 -9
- data/node_modules/inherits/inherits_browser.js +0 -27
- data/node_modules/inherits/package.json +0 -29
- data/node_modules/isarray/.npmignore +0 -1
- data/node_modules/isarray/.travis.yml +0 -4
- data/node_modules/isarray/Makefile +0 -6
- data/node_modules/isarray/README.md +0 -60
- data/node_modules/isarray/component.json +0 -19
- data/node_modules/isarray/index.js +0 -5
- data/node_modules/isarray/package.json +0 -45
- data/node_modules/isarray/test.js +0 -20
- data/node_modules/jszip/.codeclimate.yml +0 -16
- data/node_modules/jszip/.editorconfig +0 -8
- data/node_modules/jszip/.jshintignore +0 -1
- data/node_modules/jszip/.jshintrc +0 -21
- data/node_modules/jszip/.travis.yml +0 -17
- data/node_modules/jszip/CHANGES.md +0 -163
- data/node_modules/jszip/LICENSE.markdown +0 -651
- data/node_modules/jszip/README.markdown +0 -35
- data/node_modules/jszip/dist/jszip.js +0 -30
- data/node_modules/jszip/dist/jszip.min.js +0 -13
- data/node_modules/jszip/index.d.ts +0 -270
- data/node_modules/jszip/lib/base64.js +0 -106
- data/node_modules/jszip/lib/compressedObject.js +0 -74
- data/node_modules/jszip/lib/compressions.js +0 -14
- data/node_modules/jszip/lib/crc32.js +0 -77
- data/node_modules/jszip/lib/defaults.js +0 -11
- data/node_modules/jszip/lib/external.js +0 -19
- data/node_modules/jszip/lib/flate.js +0 -85
- data/node_modules/jszip/lib/generate/ZipFileWorker.js +0 -540
- data/node_modules/jszip/lib/generate/index.js +0 -57
- data/node_modules/jszip/lib/index.js +0 -52
- data/node_modules/jszip/lib/license_header.js +0 -11
- data/node_modules/jszip/lib/load.js +0 -81
- data/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +0 -74
- data/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +0 -42
- data/node_modules/jszip/lib/nodejsUtils.js +0 -57
- data/node_modules/jszip/lib/object.js +0 -389
- data/node_modules/jszip/lib/readable-stream-browser.js +0 -9
- data/node_modules/jszip/lib/reader/ArrayReader.js +0 -57
- data/node_modules/jszip/lib/reader/DataReader.js +0 -116
- data/node_modules/jszip/lib/reader/NodeBufferReader.js +0 -19
- data/node_modules/jszip/lib/reader/StringReader.js +0 -38
- data/node_modules/jszip/lib/reader/Uint8ArrayReader.js +0 -22
- data/node_modules/jszip/lib/reader/readerFor.js +0 -28
- data/node_modules/jszip/lib/signature.js +0 -7
- data/node_modules/jszip/lib/stream/ConvertWorker.js +0 -26
- data/node_modules/jszip/lib/stream/Crc32Probe.js +0 -24
- data/node_modules/jszip/lib/stream/DataLengthProbe.js +0 -29
- data/node_modules/jszip/lib/stream/DataWorker.js +0 -116
- data/node_modules/jszip/lib/stream/GenericWorker.js +0 -263
- data/node_modules/jszip/lib/stream/StreamHelper.js +0 -212
- data/node_modules/jszip/lib/support.js +0 -38
- data/node_modules/jszip/lib/utf8.js +0 -275
- data/node_modules/jszip/lib/utils.js +0 -476
- data/node_modules/jszip/lib/zipEntries.js +0 -262
- data/node_modules/jszip/lib/zipEntry.js +0 -294
- data/node_modules/jszip/lib/zipObject.js +0 -133
- data/node_modules/jszip/package.json +0 -63
- data/node_modules/jszip/vendor/FileSaver.js +0 -247
- data/node_modules/lie/README.md +0 -62
- data/node_modules/lie/dist/lie.js +0 -350
- data/node_modules/lie/dist/lie.min.js +0 -1
- data/node_modules/lie/dist/lie.polyfill.js +0 -358
- data/node_modules/lie/dist/lie.polyfill.min.js +0 -1
- data/node_modules/lie/lib/browser.js +0 -273
- data/node_modules/lie/lib/index.js +0 -298
- data/node_modules/lie/license.md +0 -7
- data/node_modules/lie/lie.d.ts +0 -244
- data/node_modules/lie/package.json +0 -69
- data/node_modules/lie/polyfill.js +0 -4
- data/node_modules/minimatch/LICENSE +0 -15
- data/node_modules/minimatch/README.md +0 -209
- data/node_modules/minimatch/minimatch.js +0 -923
- data/node_modules/minimatch/package.json +0 -30
- data/node_modules/once/LICENSE +0 -15
- data/node_modules/once/README.md +0 -79
- data/node_modules/once/once.js +0 -42
- data/node_modules/once/package.json +0 -33
- data/node_modules/pako/CHANGELOG.md +0 -164
- data/node_modules/pako/LICENSE +0 -21
- data/node_modules/pako/README.md +0 -191
- data/node_modules/pako/dist/pako.js +0 -6818
- data/node_modules/pako/dist/pako.min.js +0 -1
- data/node_modules/pako/dist/pako_deflate.js +0 -3997
- data/node_modules/pako/dist/pako_deflate.min.js +0 -1
- data/node_modules/pako/dist/pako_inflate.js +0 -3300
- data/node_modules/pako/dist/pako_inflate.min.js +0 -1
- data/node_modules/pako/index.js +0 -14
- data/node_modules/pako/lib/deflate.js +0 -400
- data/node_modules/pako/lib/inflate.js +0 -423
- data/node_modules/pako/lib/utils/common.js +0 -105
- data/node_modules/pako/lib/utils/strings.js +0 -187
- data/node_modules/pako/lib/zlib/README +0 -59
- data/node_modules/pako/lib/zlib/adler32.js +0 -51
- data/node_modules/pako/lib/zlib/constants.js +0 -68
- data/node_modules/pako/lib/zlib/crc32.js +0 -59
- data/node_modules/pako/lib/zlib/deflate.js +0 -1874
- data/node_modules/pako/lib/zlib/gzheader.js +0 -58
- data/node_modules/pako/lib/zlib/inffast.js +0 -345
- data/node_modules/pako/lib/zlib/inflate.js +0 -1556
- data/node_modules/pako/lib/zlib/inftrees.js +0 -343
- data/node_modules/pako/lib/zlib/messages.js +0 -32
- data/node_modules/pako/lib/zlib/trees.js +0 -1222
- data/node_modules/pako/lib/zlib/zstream.js +0 -47
- data/node_modules/pako/package.json +0 -44
- data/node_modules/path-is-absolute/index.js +0 -20
- data/node_modules/path-is-absolute/license +0 -21
- data/node_modules/path-is-absolute/package.json +0 -43
- data/node_modules/path-is-absolute/readme.md +0 -59
- data/node_modules/process-nextick-args/index.js +0 -45
- data/node_modules/process-nextick-args/license.md +0 -19
- data/node_modules/process-nextick-args/package.json +0 -25
- data/node_modules/process-nextick-args/readme.md +0 -18
- data/node_modules/readable-stream/.travis.yml +0 -34
- data/node_modules/readable-stream/CONTRIBUTING.md +0 -38
- data/node_modules/readable-stream/GOVERNANCE.md +0 -136
- data/node_modules/readable-stream/LICENSE +0 -47
- data/node_modules/readable-stream/README.md +0 -58
- data/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
- data/node_modules/readable-stream/duplex-browser.js +0 -1
- data/node_modules/readable-stream/duplex.js +0 -1
- data/node_modules/readable-stream/lib/_stream_duplex.js +0 -131
- data/node_modules/readable-stream/lib/_stream_passthrough.js +0 -47
- data/node_modules/readable-stream/lib/_stream_readable.js +0 -1019
- data/node_modules/readable-stream/lib/_stream_transform.js +0 -214
- data/node_modules/readable-stream/lib/_stream_writable.js +0 -687
- data/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
- data/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
- data/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
- data/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
- data/node_modules/readable-stream/package.json +0 -52
- data/node_modules/readable-stream/passthrough.js +0 -1
- data/node_modules/readable-stream/readable-browser.js +0 -7
- data/node_modules/readable-stream/readable.js +0 -19
- data/node_modules/readable-stream/transform.js +0 -1
- data/node_modules/readable-stream/writable-browser.js +0 -1
- data/node_modules/readable-stream/writable.js +0 -8
- data/node_modules/rimraf/LICENSE +0 -15
- data/node_modules/rimraf/README.md +0 -101
- data/node_modules/rimraf/bin.js +0 -50
- data/node_modules/rimraf/package.json +0 -29
- data/node_modules/rimraf/rimraf.js +0 -372
- data/node_modules/safe-buffer/LICENSE +0 -21
- data/node_modules/safe-buffer/README.md +0 -584
- data/node_modules/safe-buffer/index.d.ts +0 -187
- data/node_modules/safe-buffer/index.js +0 -62
- data/node_modules/safe-buffer/package.json +0 -37
- data/node_modules/selenium-webdriver/CHANGES.md +0 -1114
- data/node_modules/selenium-webdriver/LICENSE +0 -202
- data/node_modules/selenium-webdriver/NOTICE +0 -2
- data/node_modules/selenium-webdriver/README.md +0 -229
- data/node_modules/selenium-webdriver/chrome.js +0 -295
- data/node_modules/selenium-webdriver/chromium.js +0 -829
- data/node_modules/selenium-webdriver/devtools/CDPConnection.js +0 -35
- data/node_modules/selenium-webdriver/edge.js +0 -224
- data/node_modules/selenium-webdriver/example/chrome_android.js +0 -45
- data/node_modules/selenium-webdriver/example/chrome_mobile_emulation.js +0 -46
- data/node_modules/selenium-webdriver/example/firefox_channels.js +0 -84
- data/node_modules/selenium-webdriver/example/google_search.js +0 -50
- data/node_modules/selenium-webdriver/example/google_search_test.js +0 -70
- data/node_modules/selenium-webdriver/example/headless.js +0 -63
- data/node_modules/selenium-webdriver/example/logging.js +0 -64
- data/node_modules/selenium-webdriver/firefox.js +0 -789
- data/node_modules/selenium-webdriver/http/index.js +0 -324
- data/node_modules/selenium-webdriver/http/util.js +0 -172
- data/node_modules/selenium-webdriver/ie.js +0 -503
- data/node_modules/selenium-webdriver/index.js +0 -825
- data/node_modules/selenium-webdriver/io/exec.js +0 -162
- data/node_modules/selenium-webdriver/io/index.js +0 -348
- data/node_modules/selenium-webdriver/io/zip.js +0 -223
- data/node_modules/selenium-webdriver/lib/atoms/find-elements.js +0 -123
- data/node_modules/selenium-webdriver/lib/atoms/get-attribute.js +0 -101
- data/node_modules/selenium-webdriver/lib/atoms/is-displayed.js +0 -101
- data/node_modules/selenium-webdriver/lib/atoms/mutation-listener.js +0 -55
- data/node_modules/selenium-webdriver/lib/by.js +0 -415
- data/node_modules/selenium-webdriver/lib/capabilities.js +0 -553
- data/node_modules/selenium-webdriver/lib/command.js +0 -206
- data/node_modules/selenium-webdriver/lib/error.js +0 -605
- data/node_modules/selenium-webdriver/lib/http.js +0 -704
- data/node_modules/selenium-webdriver/lib/input.js +0 -946
- data/node_modules/selenium-webdriver/lib/logging.js +0 -661
- data/node_modules/selenium-webdriver/lib/promise.js +0 -285
- data/node_modules/selenium-webdriver/lib/proxy.js +0 -212
- data/node_modules/selenium-webdriver/lib/session.js +0 -77
- data/node_modules/selenium-webdriver/lib/symbols.js +0 -37
- data/node_modules/selenium-webdriver/lib/until.js +0 -429
- data/node_modules/selenium-webdriver/lib/webdriver.js +0 -2919
- data/node_modules/selenium-webdriver/net/index.js +0 -107
- data/node_modules/selenium-webdriver/net/portprober.js +0 -75
- data/node_modules/selenium-webdriver/opera.js +0 -406
- data/node_modules/selenium-webdriver/package.json +0 -54
- data/node_modules/selenium-webdriver/proxy.js +0 -32
- data/node_modules/selenium-webdriver/remote/index.js +0 -624
- data/node_modules/selenium-webdriver/safari.js +0 -168
- data/node_modules/selenium-webdriver/testing/index.js +0 -504
- data/node_modules/set-immediate-shim/index.js +0 -7
- data/node_modules/set-immediate-shim/package.json +0 -34
- data/node_modules/set-immediate-shim/readme.md +0 -31
- data/node_modules/string_decoder/.travis.yml +0 -50
- data/node_modules/string_decoder/LICENSE +0 -48
- data/node_modules/string_decoder/README.md +0 -47
- data/node_modules/string_decoder/lib/string_decoder.js +0 -296
- data/node_modules/string_decoder/package.json +0 -31
- data/node_modules/tmp/CHANGELOG.md +0 -288
- data/node_modules/tmp/LICENSE +0 -21
- data/node_modules/tmp/README.md +0 -365
- data/node_modules/tmp/lib/tmp.js +0 -780
- data/node_modules/tmp/node_modules/.bin/rimraf +0 -1
- data/node_modules/tmp/node_modules/rimraf/CHANGELOG.md +0 -65
- data/node_modules/tmp/node_modules/rimraf/LICENSE +0 -15
- data/node_modules/tmp/node_modules/rimraf/README.md +0 -101
- data/node_modules/tmp/node_modules/rimraf/bin.js +0 -68
- data/node_modules/tmp/node_modules/rimraf/package.json +0 -32
- data/node_modules/tmp/node_modules/rimraf/rimraf.js +0 -360
- data/node_modules/tmp/package.json +0 -58
- data/node_modules/util-deprecate/History.md +0 -16
- data/node_modules/util-deprecate/LICENSE +0 -24
- data/node_modules/util-deprecate/README.md +0 -53
- data/node_modules/util-deprecate/browser.js +0 -67
- data/node_modules/util-deprecate/node.js +0 -6
- data/node_modules/util-deprecate/package.json +0 -27
- data/node_modules/wrappy/LICENSE +0 -15
- data/node_modules/wrappy/README.md +0 -36
- data/node_modules/wrappy/package.json +0 -29
- data/node_modules/wrappy/wrappy.js +0 -33
- data/node_modules/ws/LICENSE +0 -21
- data/node_modules/ws/README.md +0 -496
- data/node_modules/ws/browser.js +0 -8
- data/node_modules/ws/index.js +0 -10
- data/node_modules/ws/lib/buffer-util.js +0 -129
- data/node_modules/ws/lib/constants.js +0 -10
- data/node_modules/ws/lib/event-target.js +0 -184
- data/node_modules/ws/lib/extension.js +0 -223
- data/node_modules/ws/lib/limiter.js +0 -55
- data/node_modules/ws/lib/permessage-deflate.js +0 -517
- data/node_modules/ws/lib/receiver.js +0 -507
- data/node_modules/ws/lib/sender.js +0 -405
- data/node_modules/ws/lib/stream.js +0 -165
- data/node_modules/ws/lib/validation.js +0 -104
- data/node_modules/ws/lib/websocket-server.js +0 -418
- data/node_modules/ws/lib/websocket.js +0 -942
- data/node_modules/ws/package.json +0 -56
- data/package-lock.json +0 -458
- data/package.json +0 -5
- data/selenium.log +0 -1
- data/spec.md +0 -6
- data/test.data +0 -2110
data/node_modules/tmp/lib/tmp.js
DELETED
@@ -1,780 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* Tmp
|
3
|
-
*
|
4
|
-
* Copyright (c) 2011-2017 KARASZI Istvan <github@spam.raszi.hu>
|
5
|
-
*
|
6
|
-
* MIT Licensed
|
7
|
-
*/
|
8
|
-
|
9
|
-
/*
|
10
|
-
* Module dependencies.
|
11
|
-
*/
|
12
|
-
const fs = require('fs');
|
13
|
-
const os = require('os');
|
14
|
-
const path = require('path');
|
15
|
-
const crypto = require('crypto');
|
16
|
-
const _c = { fs: fs.constants, os: os.constants };
|
17
|
-
const rimraf = require('rimraf');
|
18
|
-
|
19
|
-
/*
|
20
|
-
* The working inner variables.
|
21
|
-
*/
|
22
|
-
const
|
23
|
-
// the random characters to choose from
|
24
|
-
RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
25
|
-
|
26
|
-
TEMPLATE_PATTERN = /XXXXXX/,
|
27
|
-
|
28
|
-
DEFAULT_TRIES = 3,
|
29
|
-
|
30
|
-
CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
|
31
|
-
|
32
|
-
// constants are off on the windows platform and will not match the actual errno codes
|
33
|
-
IS_WIN32 = os.platform() === 'win32',
|
34
|
-
EBADF = _c.EBADF || _c.os.errno.EBADF,
|
35
|
-
ENOENT = _c.ENOENT || _c.os.errno.ENOENT,
|
36
|
-
|
37
|
-
DIR_MODE = 0o700 /* 448 */,
|
38
|
-
FILE_MODE = 0o600 /* 384 */,
|
39
|
-
|
40
|
-
EXIT = 'exit',
|
41
|
-
|
42
|
-
// this will hold the objects need to be removed on exit
|
43
|
-
_removeObjects = [],
|
44
|
-
|
45
|
-
// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
|
46
|
-
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
|
47
|
-
FN_RIMRAF_SYNC = rimraf.sync;
|
48
|
-
|
49
|
-
let
|
50
|
-
_gracefulCleanup = false;
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Gets a temporary file name.
|
54
|
-
*
|
55
|
-
* @param {(Options|tmpNameCallback)} options options or callback
|
56
|
-
* @param {?tmpNameCallback} callback the callback function
|
57
|
-
*/
|
58
|
-
function tmpName(options, callback) {
|
59
|
-
const
|
60
|
-
args = _parseArguments(options, callback),
|
61
|
-
opts = args[0],
|
62
|
-
cb = args[1];
|
63
|
-
|
64
|
-
try {
|
65
|
-
_assertAndSanitizeOptions(opts);
|
66
|
-
} catch (err) {
|
67
|
-
return cb(err);
|
68
|
-
}
|
69
|
-
|
70
|
-
let tries = opts.tries;
|
71
|
-
(function _getUniqueName() {
|
72
|
-
try {
|
73
|
-
const name = _generateTmpName(opts);
|
74
|
-
|
75
|
-
// check whether the path exists then retry if needed
|
76
|
-
fs.stat(name, function (err) {
|
77
|
-
/* istanbul ignore else */
|
78
|
-
if (!err) {
|
79
|
-
/* istanbul ignore else */
|
80
|
-
if (tries-- > 0) return _getUniqueName();
|
81
|
-
|
82
|
-
return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
|
83
|
-
}
|
84
|
-
|
85
|
-
cb(null, name);
|
86
|
-
});
|
87
|
-
} catch (err) {
|
88
|
-
cb(err);
|
89
|
-
}
|
90
|
-
}());
|
91
|
-
}
|
92
|
-
|
93
|
-
/**
|
94
|
-
* Synchronous version of tmpName.
|
95
|
-
*
|
96
|
-
* @param {Object} options
|
97
|
-
* @returns {string} the generated random name
|
98
|
-
* @throws {Error} if the options are invalid or could not generate a filename
|
99
|
-
*/
|
100
|
-
function tmpNameSync(options) {
|
101
|
-
const
|
102
|
-
args = _parseArguments(options),
|
103
|
-
opts = args[0];
|
104
|
-
|
105
|
-
_assertAndSanitizeOptions(opts);
|
106
|
-
|
107
|
-
let tries = opts.tries;
|
108
|
-
do {
|
109
|
-
const name = _generateTmpName(opts);
|
110
|
-
try {
|
111
|
-
fs.statSync(name);
|
112
|
-
} catch (e) {
|
113
|
-
return name;
|
114
|
-
}
|
115
|
-
} while (tries-- > 0);
|
116
|
-
|
117
|
-
throw new Error('Could not get a unique tmp filename, max tries reached');
|
118
|
-
}
|
119
|
-
|
120
|
-
/**
|
121
|
-
* Creates and opens a temporary file.
|
122
|
-
*
|
123
|
-
* @param {(Options|null|undefined|fileCallback)} options the config options or the callback function or null or undefined
|
124
|
-
* @param {?fileCallback} callback
|
125
|
-
*/
|
126
|
-
function file(options, callback) {
|
127
|
-
const
|
128
|
-
args = _parseArguments(options, callback),
|
129
|
-
opts = args[0],
|
130
|
-
cb = args[1];
|
131
|
-
|
132
|
-
// gets a temporary filename
|
133
|
-
tmpName(opts, function _tmpNameCreated(err, name) {
|
134
|
-
/* istanbul ignore else */
|
135
|
-
if (err) return cb(err);
|
136
|
-
|
137
|
-
// create and open the file
|
138
|
-
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
|
139
|
-
/* istanbu ignore else */
|
140
|
-
if (err) return cb(err);
|
141
|
-
|
142
|
-
if (opts.discardDescriptor) {
|
143
|
-
return fs.close(fd, function _discardCallback(possibleErr) {
|
144
|
-
// the chance of getting an error on close here is rather low and might occur in the most edgiest cases only
|
145
|
-
return cb(possibleErr, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts, false));
|
146
|
-
});
|
147
|
-
} else {
|
148
|
-
// detachDescriptor passes the descriptor whereas discardDescriptor closes it, either way, we no longer care
|
149
|
-
// about the descriptor
|
150
|
-
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
151
|
-
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, false));
|
152
|
-
}
|
153
|
-
});
|
154
|
-
});
|
155
|
-
}
|
156
|
-
|
157
|
-
/**
|
158
|
-
* Synchronous version of file.
|
159
|
-
*
|
160
|
-
* @param {Options} options
|
161
|
-
* @returns {FileSyncObject} object consists of name, fd and removeCallback
|
162
|
-
* @throws {Error} if cannot create a file
|
163
|
-
*/
|
164
|
-
function fileSync(options) {
|
165
|
-
const
|
166
|
-
args = _parseArguments(options),
|
167
|
-
opts = args[0];
|
168
|
-
|
169
|
-
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
170
|
-
const name = tmpNameSync(opts);
|
171
|
-
var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
|
172
|
-
/* istanbul ignore else */
|
173
|
-
if (opts.discardDescriptor) {
|
174
|
-
fs.closeSync(fd);
|
175
|
-
fd = undefined;
|
176
|
-
}
|
177
|
-
|
178
|
-
return {
|
179
|
-
name: name,
|
180
|
-
fd: fd,
|
181
|
-
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, true)
|
182
|
-
};
|
183
|
-
}
|
184
|
-
|
185
|
-
/**
|
186
|
-
* Creates a temporary directory.
|
187
|
-
*
|
188
|
-
* @param {(Options|dirCallback)} options the options or the callback function
|
189
|
-
* @param {?dirCallback} callback
|
190
|
-
*/
|
191
|
-
function dir(options, callback) {
|
192
|
-
const
|
193
|
-
args = _parseArguments(options, callback),
|
194
|
-
opts = args[0],
|
195
|
-
cb = args[1];
|
196
|
-
|
197
|
-
// gets a temporary filename
|
198
|
-
tmpName(opts, function _tmpNameCreated(err, name) {
|
199
|
-
/* istanbul ignore else */
|
200
|
-
if (err) return cb(err);
|
201
|
-
|
202
|
-
// create the directory
|
203
|
-
fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
|
204
|
-
/* istanbul ignore else */
|
205
|
-
if (err) return cb(err);
|
206
|
-
|
207
|
-
cb(null, name, _prepareTmpDirRemoveCallback(name, opts, false));
|
208
|
-
});
|
209
|
-
});
|
210
|
-
}
|
211
|
-
|
212
|
-
/**
|
213
|
-
* Synchronous version of dir.
|
214
|
-
*
|
215
|
-
* @param {Options} options
|
216
|
-
* @returns {DirSyncObject} object consists of name and removeCallback
|
217
|
-
* @throws {Error} if it cannot create a directory
|
218
|
-
*/
|
219
|
-
function dirSync(options) {
|
220
|
-
const
|
221
|
-
args = _parseArguments(options),
|
222
|
-
opts = args[0];
|
223
|
-
|
224
|
-
const name = tmpNameSync(opts);
|
225
|
-
fs.mkdirSync(name, opts.mode || DIR_MODE);
|
226
|
-
|
227
|
-
return {
|
228
|
-
name: name,
|
229
|
-
removeCallback: _prepareTmpDirRemoveCallback(name, opts, true)
|
230
|
-
};
|
231
|
-
}
|
232
|
-
|
233
|
-
/**
|
234
|
-
* Removes files asynchronously.
|
235
|
-
*
|
236
|
-
* @param {Object} fdPath
|
237
|
-
* @param {Function} next
|
238
|
-
* @private
|
239
|
-
*/
|
240
|
-
function _removeFileAsync(fdPath, next) {
|
241
|
-
const _handler = function (err) {
|
242
|
-
if (err && !_isENOENT(err)) {
|
243
|
-
// reraise any unanticipated error
|
244
|
-
return next(err);
|
245
|
-
}
|
246
|
-
next();
|
247
|
-
};
|
248
|
-
|
249
|
-
if (0 <= fdPath[0])
|
250
|
-
fs.close(fdPath[0], function () {
|
251
|
-
fs.unlink(fdPath[1], _handler);
|
252
|
-
});
|
253
|
-
else fs.unlink(fdPath[1], _handler);
|
254
|
-
}
|
255
|
-
|
256
|
-
/**
|
257
|
-
* Removes files synchronously.
|
258
|
-
*
|
259
|
-
* @param {Object} fdPath
|
260
|
-
* @private
|
261
|
-
*/
|
262
|
-
function _removeFileSync(fdPath) {
|
263
|
-
let rethrownException = null;
|
264
|
-
try {
|
265
|
-
if (0 <= fdPath[0]) fs.closeSync(fdPath[0]);
|
266
|
-
} catch (e) {
|
267
|
-
// reraise any unanticipated error
|
268
|
-
if (!_isEBADF(e) && !_isENOENT(e)) throw e;
|
269
|
-
} finally {
|
270
|
-
try {
|
271
|
-
fs.unlinkSync(fdPath[1]);
|
272
|
-
}
|
273
|
-
catch (e) {
|
274
|
-
// reraise any unanticipated error
|
275
|
-
if (!_isENOENT(e)) rethrownException = e;
|
276
|
-
}
|
277
|
-
}
|
278
|
-
if (rethrownException !== null) {
|
279
|
-
throw rethrownException;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
/**
|
284
|
-
* Prepares the callback for removal of the temporary file.
|
285
|
-
*
|
286
|
-
* Returns either a sync callback or a async callback depending on whether
|
287
|
-
* fileSync or file was called, which is expressed by the sync parameter.
|
288
|
-
*
|
289
|
-
* @param {string} name the path of the file
|
290
|
-
* @param {number} fd file descriptor
|
291
|
-
* @param {Object} opts
|
292
|
-
* @param {boolean} sync
|
293
|
-
* @returns {fileCallback | fileCallbackSync}
|
294
|
-
* @private
|
295
|
-
*/
|
296
|
-
function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
|
297
|
-
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name], sync);
|
298
|
-
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], sync, removeCallbackSync);
|
299
|
-
|
300
|
-
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
301
|
-
|
302
|
-
return sync ? removeCallbackSync : removeCallback;
|
303
|
-
}
|
304
|
-
|
305
|
-
/**
|
306
|
-
* Prepares the callback for removal of the temporary directory.
|
307
|
-
*
|
308
|
-
* Returns either a sync callback or a async callback depending on whether
|
309
|
-
* tmpFileSync or tmpFile was called, which is expressed by the sync parameter.
|
310
|
-
*
|
311
|
-
* @param {string} name
|
312
|
-
* @param {Object} opts
|
313
|
-
* @param {boolean} sync
|
314
|
-
* @returns {Function} the callback
|
315
|
-
* @private
|
316
|
-
*/
|
317
|
-
function _prepareTmpDirRemoveCallback(name, opts, sync) {
|
318
|
-
const removeFunction = opts.unsafeCleanup ? rimraf : fs.rmdir.bind(fs);
|
319
|
-
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
|
320
|
-
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
|
321
|
-
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
|
322
|
-
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
323
|
-
|
324
|
-
return sync ? removeCallbackSync : removeCallback;
|
325
|
-
}
|
326
|
-
|
327
|
-
/**
|
328
|
-
* Creates a guarded function wrapping the removeFunction call.
|
329
|
-
*
|
330
|
-
* The cleanup callback is save to be called multiple times.
|
331
|
-
* Subsequent invocations will be ignored.
|
332
|
-
*
|
333
|
-
* @param {Function} removeFunction
|
334
|
-
* @param {string} fileOrDirName
|
335
|
-
* @param {boolean} sync
|
336
|
-
* @param {cleanupCallbackSync?} cleanupCallbackSync
|
337
|
-
* @returns {cleanupCallback | cleanupCallbackSync}
|
338
|
-
* @private
|
339
|
-
*/
|
340
|
-
function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCallbackSync) {
|
341
|
-
let called = false;
|
342
|
-
|
343
|
-
// if sync is true, the next parameter will be ignored
|
344
|
-
return function _cleanupCallback(next) {
|
345
|
-
|
346
|
-
/* istanbul ignore else */
|
347
|
-
if (!called) {
|
348
|
-
// remove cleanupCallback from cache
|
349
|
-
const toRemove = cleanupCallbackSync || _cleanupCallback;
|
350
|
-
const index = _removeObjects.indexOf(toRemove);
|
351
|
-
/* istanbul ignore else */
|
352
|
-
if (index >= 0) _removeObjects.splice(index, 1);
|
353
|
-
|
354
|
-
called = true;
|
355
|
-
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
|
356
|
-
return removeFunction(fileOrDirName);
|
357
|
-
} else {
|
358
|
-
return removeFunction(fileOrDirName, next || function() {});
|
359
|
-
}
|
360
|
-
}
|
361
|
-
};
|
362
|
-
}
|
363
|
-
|
364
|
-
/**
|
365
|
-
* The garbage collector.
|
366
|
-
*
|
367
|
-
* @private
|
368
|
-
*/
|
369
|
-
function _garbageCollector() {
|
370
|
-
/* istanbul ignore else */
|
371
|
-
if (!_gracefulCleanup) return;
|
372
|
-
|
373
|
-
// the function being called removes itself from _removeObjects,
|
374
|
-
// loop until _removeObjects is empty
|
375
|
-
while (_removeObjects.length) {
|
376
|
-
try {
|
377
|
-
_removeObjects[0]();
|
378
|
-
} catch (e) {
|
379
|
-
// already removed?
|
380
|
-
}
|
381
|
-
}
|
382
|
-
}
|
383
|
-
|
384
|
-
/**
|
385
|
-
* Random name generator based on crypto.
|
386
|
-
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
387
|
-
*
|
388
|
-
* @param {number} howMany
|
389
|
-
* @returns {string} the generated random name
|
390
|
-
* @private
|
391
|
-
*/
|
392
|
-
function _randomChars(howMany) {
|
393
|
-
let
|
394
|
-
value = [],
|
395
|
-
rnd = null;
|
396
|
-
|
397
|
-
// make sure that we do not fail because we ran out of entropy
|
398
|
-
try {
|
399
|
-
rnd = crypto.randomBytes(howMany);
|
400
|
-
} catch (e) {
|
401
|
-
rnd = crypto.pseudoRandomBytes(howMany);
|
402
|
-
}
|
403
|
-
|
404
|
-
for (var i = 0; i < howMany; i++) {
|
405
|
-
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
406
|
-
}
|
407
|
-
|
408
|
-
return value.join('');
|
409
|
-
}
|
410
|
-
|
411
|
-
/**
|
412
|
-
* Helper which determines whether a string s is blank, that is undefined, or empty or null.
|
413
|
-
*
|
414
|
-
* @private
|
415
|
-
* @param {string} s
|
416
|
-
* @returns {Boolean} true whether the string s is blank, false otherwise
|
417
|
-
*/
|
418
|
-
function _isBlank(s) {
|
419
|
-
return s === null || _isUndefined(s) || !s.trim();
|
420
|
-
}
|
421
|
-
|
422
|
-
/**
|
423
|
-
* Checks whether the `obj` parameter is defined or not.
|
424
|
-
*
|
425
|
-
* @param {Object} obj
|
426
|
-
* @returns {boolean} true if the object is undefined
|
427
|
-
* @private
|
428
|
-
*/
|
429
|
-
function _isUndefined(obj) {
|
430
|
-
return typeof obj === 'undefined';
|
431
|
-
}
|
432
|
-
|
433
|
-
/**
|
434
|
-
* Parses the function arguments.
|
435
|
-
*
|
436
|
-
* This function helps to have optional arguments.
|
437
|
-
*
|
438
|
-
* @param {(Options|null|undefined|Function)} options
|
439
|
-
* @param {?Function} callback
|
440
|
-
* @returns {Array} parsed arguments
|
441
|
-
* @private
|
442
|
-
*/
|
443
|
-
function _parseArguments(options, callback) {
|
444
|
-
/* istanbul ignore else */
|
445
|
-
if (typeof options === 'function') {
|
446
|
-
return [{}, options];
|
447
|
-
}
|
448
|
-
|
449
|
-
/* istanbul ignore else */
|
450
|
-
if (_isUndefined(options)) {
|
451
|
-
return [{}, callback];
|
452
|
-
}
|
453
|
-
|
454
|
-
// copy options so we do not leak the changes we make internally
|
455
|
-
const actualOptions = {};
|
456
|
-
for (const key of Object.getOwnPropertyNames(options)) {
|
457
|
-
actualOptions[key] = options[key];
|
458
|
-
}
|
459
|
-
|
460
|
-
return [actualOptions, callback];
|
461
|
-
}
|
462
|
-
|
463
|
-
/**
|
464
|
-
* Generates a new temporary name.
|
465
|
-
*
|
466
|
-
* @param {Object} opts
|
467
|
-
* @returns {string} the new random name according to opts
|
468
|
-
* @private
|
469
|
-
*/
|
470
|
-
function _generateTmpName(opts) {
|
471
|
-
|
472
|
-
const tmpDir = opts.tmpdir;
|
473
|
-
|
474
|
-
/* istanbul ignore else */
|
475
|
-
if (!_isUndefined(opts.name))
|
476
|
-
return path.join(tmpDir, opts.dir, opts.name);
|
477
|
-
|
478
|
-
/* istanbul ignore else */
|
479
|
-
if (!_isUndefined(opts.template))
|
480
|
-
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
|
481
|
-
|
482
|
-
// prefix and postfix
|
483
|
-
const name = [
|
484
|
-
opts.prefix ? opts.prefix : 'tmp',
|
485
|
-
'-',
|
486
|
-
process.pid,
|
487
|
-
'-',
|
488
|
-
_randomChars(12),
|
489
|
-
opts.postfix ? '-' + opts.postfix : ''
|
490
|
-
].join('');
|
491
|
-
|
492
|
-
return path.join(tmpDir, opts.dir, name);
|
493
|
-
}
|
494
|
-
|
495
|
-
/**
|
496
|
-
* Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
|
497
|
-
* options.
|
498
|
-
*
|
499
|
-
* @param {Options} options
|
500
|
-
* @private
|
501
|
-
*/
|
502
|
-
function _assertAndSanitizeOptions(options) {
|
503
|
-
|
504
|
-
options.tmpdir = _getTmpDir(options);
|
505
|
-
|
506
|
-
const tmpDir = options.tmpdir;
|
507
|
-
|
508
|
-
/* istanbul ignore else */
|
509
|
-
if (!_isUndefined(options.name))
|
510
|
-
_assertIsRelative(options.name, 'name', tmpDir);
|
511
|
-
/* istanbul ignore else */
|
512
|
-
if (!_isUndefined(options.dir))
|
513
|
-
_assertIsRelative(options.dir, 'dir', tmpDir);
|
514
|
-
/* istanbul ignore else */
|
515
|
-
if (!_isUndefined(options.template)) {
|
516
|
-
_assertIsRelative(options.template, 'template', tmpDir);
|
517
|
-
if (!options.template.match(TEMPLATE_PATTERN))
|
518
|
-
throw new Error(`Invalid template, found "${options.template}".`);
|
519
|
-
}
|
520
|
-
/* istanbul ignore else */
|
521
|
-
if (!_isUndefined(options.tries) && isNaN(options.tries) || options.tries < 0)
|
522
|
-
throw new Error(`Invalid tries, found "${options.tries}".`);
|
523
|
-
|
524
|
-
// if a name was specified we will try once
|
525
|
-
options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
|
526
|
-
options.keep = !!options.keep;
|
527
|
-
options.detachDescriptor = !!options.detachDescriptor;
|
528
|
-
options.discardDescriptor = !!options.discardDescriptor;
|
529
|
-
options.unsafeCleanup = !!options.unsafeCleanup;
|
530
|
-
|
531
|
-
// sanitize dir, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
532
|
-
options.dir = _isUndefined(options.dir) ? '' : path.relative(tmpDir, _resolvePath(options.dir, tmpDir));
|
533
|
-
options.template = _isUndefined(options.template) ? undefined : path.relative(tmpDir, _resolvePath(options.template, tmpDir));
|
534
|
-
// sanitize further if template is relative to options.dir
|
535
|
-
options.template = _isBlank(options.template) ? undefined : path.relative(options.dir, options.template);
|
536
|
-
|
537
|
-
// for completeness' sake only, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
538
|
-
options.name = _isUndefined(options.name) ? undefined : _sanitizeName(options.name);
|
539
|
-
options.prefix = _isUndefined(options.prefix) ? '' : options.prefix;
|
540
|
-
options.postfix = _isUndefined(options.postfix) ? '' : options.postfix;
|
541
|
-
}
|
542
|
-
|
543
|
-
/**
|
544
|
-
* Resolve the specified path name in respect to tmpDir.
|
545
|
-
*
|
546
|
-
* The specified name might include relative path components, e.g. ../
|
547
|
-
* so we need to resolve in order to be sure that is is located inside tmpDir
|
548
|
-
*
|
549
|
-
* @param name
|
550
|
-
* @param tmpDir
|
551
|
-
* @returns {string}
|
552
|
-
* @private
|
553
|
-
*/
|
554
|
-
function _resolvePath(name, tmpDir) {
|
555
|
-
const sanitizedName = _sanitizeName(name);
|
556
|
-
if (sanitizedName.startsWith(tmpDir)) {
|
557
|
-
return path.resolve(sanitizedName);
|
558
|
-
} else {
|
559
|
-
return path.resolve(path.join(tmpDir, sanitizedName));
|
560
|
-
}
|
561
|
-
}
|
562
|
-
|
563
|
-
/**
|
564
|
-
* Sanitize the specified path name by removing all quote characters.
|
565
|
-
*
|
566
|
-
* @param name
|
567
|
-
* @returns {string}
|
568
|
-
* @private
|
569
|
-
*/
|
570
|
-
function _sanitizeName(name) {
|
571
|
-
if (_isBlank(name)) {
|
572
|
-
return name;
|
573
|
-
}
|
574
|
-
return name.replace(/["']/g, '');
|
575
|
-
}
|
576
|
-
|
577
|
-
/**
|
578
|
-
* Asserts whether specified name is relative to the specified tmpDir.
|
579
|
-
*
|
580
|
-
* @param {string} name
|
581
|
-
* @param {string} option
|
582
|
-
* @param {string} tmpDir
|
583
|
-
* @throws {Error}
|
584
|
-
* @private
|
585
|
-
*/
|
586
|
-
function _assertIsRelative(name, option, tmpDir) {
|
587
|
-
if (option === 'name') {
|
588
|
-
// assert that name is not absolute and does not contain a path
|
589
|
-
if (path.isAbsolute(name))
|
590
|
-
throw new Error(`${option} option must not contain an absolute path, found "${name}".`);
|
591
|
-
// must not fail on valid .<name> or ..<name> or similar such constructs
|
592
|
-
let basename = path.basename(name);
|
593
|
-
if (basename === '..' || basename === '.' || basename !== name)
|
594
|
-
throw new Error(`${option} option must not contain a path, found "${name}".`);
|
595
|
-
}
|
596
|
-
else { // if (option === 'dir' || option === 'template') {
|
597
|
-
// assert that dir or template are relative to tmpDir
|
598
|
-
if (path.isAbsolute(name) && !name.startsWith(tmpDir)) {
|
599
|
-
throw new Error(`${option} option must be relative to "${tmpDir}", found "${name}".`);
|
600
|
-
}
|
601
|
-
let resolvedPath = _resolvePath(name, tmpDir);
|
602
|
-
if (!resolvedPath.startsWith(tmpDir))
|
603
|
-
throw new Error(`${option} option must be relative to "${tmpDir}", found "${resolvedPath}".`);
|
604
|
-
}
|
605
|
-
}
|
606
|
-
|
607
|
-
/**
|
608
|
-
* Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
|
609
|
-
*
|
610
|
-
* @private
|
611
|
-
*/
|
612
|
-
function _isEBADF(error) {
|
613
|
-
return _isExpectedError(error, -EBADF, 'EBADF');
|
614
|
-
}
|
615
|
-
|
616
|
-
/**
|
617
|
-
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
|
618
|
-
*
|
619
|
-
* @private
|
620
|
-
*/
|
621
|
-
function _isENOENT(error) {
|
622
|
-
return _isExpectedError(error, -ENOENT, 'ENOENT');
|
623
|
-
}
|
624
|
-
|
625
|
-
/**
|
626
|
-
* Helper to determine whether the expected error code matches the actual code and errno,
|
627
|
-
* which will differ between the supported node versions.
|
628
|
-
*
|
629
|
-
* - Node >= 7.0:
|
630
|
-
* error.code {string}
|
631
|
-
* error.errno {number} any numerical value will be negated
|
632
|
-
*
|
633
|
-
* CAVEAT
|
634
|
-
*
|
635
|
-
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
|
636
|
-
* is no different here.
|
637
|
-
*
|
638
|
-
* @param {SystemError} error
|
639
|
-
* @param {number} errno
|
640
|
-
* @param {string} code
|
641
|
-
* @private
|
642
|
-
*/
|
643
|
-
function _isExpectedError(error, errno, code) {
|
644
|
-
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
|
645
|
-
}
|
646
|
-
|
647
|
-
/**
|
648
|
-
* Sets the graceful cleanup.
|
649
|
-
*
|
650
|
-
* If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the
|
651
|
-
* temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary
|
652
|
-
* object removals.
|
653
|
-
*/
|
654
|
-
function setGracefulCleanup() {
|
655
|
-
_gracefulCleanup = true;
|
656
|
-
}
|
657
|
-
|
658
|
-
/**
|
659
|
-
* Returns the currently configured tmp dir from os.tmpdir().
|
660
|
-
*
|
661
|
-
* @private
|
662
|
-
* @param {?Options} options
|
663
|
-
* @returns {string} the currently configured tmp dir
|
664
|
-
*/
|
665
|
-
function _getTmpDir(options) {
|
666
|
-
return path.resolve(_sanitizeName(options && options.tmpdir || os.tmpdir()));
|
667
|
-
}
|
668
|
-
|
669
|
-
// Install process exit listener
|
670
|
-
process.addListener(EXIT, _garbageCollector);
|
671
|
-
|
672
|
-
/**
|
673
|
-
* Configuration options.
|
674
|
-
*
|
675
|
-
* @typedef {Object} Options
|
676
|
-
* @property {?boolean} keep the temporary object (file or dir) will not be garbage collected
|
677
|
-
* @property {?number} tries the number of tries before give up the name generation
|
678
|
-
* @property (?int) mode the access mode, defaults are 0o700 for directories and 0o600 for files
|
679
|
-
* @property {?string} template the "mkstemp" like filename template
|
680
|
-
* @property {?string} name fixed name relative to tmpdir or the specified dir option
|
681
|
-
* @property {?string} dir tmp directory relative to the root tmp directory in use
|
682
|
-
* @property {?string} prefix prefix for the generated name
|
683
|
-
* @property {?string} postfix postfix for the generated name
|
684
|
-
* @property {?string} tmpdir the root tmp directory which overrides the os tmpdir
|
685
|
-
* @property {?boolean} unsafeCleanup recursively removes the created temporary directory, even when it's not empty
|
686
|
-
* @property {?boolean} detachDescriptor detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
|
687
|
-
* @property {?boolean} discardDescriptor discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection
|
688
|
-
*/
|
689
|
-
|
690
|
-
/**
|
691
|
-
* @typedef {Object} FileSyncObject
|
692
|
-
* @property {string} name the name of the file
|
693
|
-
* @property {string} fd the file descriptor or -1 if the fd has been discarded
|
694
|
-
* @property {fileCallback} removeCallback the callback function to remove the file
|
695
|
-
*/
|
696
|
-
|
697
|
-
/**
|
698
|
-
* @typedef {Object} DirSyncObject
|
699
|
-
* @property {string} name the name of the directory
|
700
|
-
* @property {fileCallback} removeCallback the callback function to remove the directory
|
701
|
-
*/
|
702
|
-
|
703
|
-
/**
|
704
|
-
* @callback tmpNameCallback
|
705
|
-
* @param {?Error} err the error object if anything goes wrong
|
706
|
-
* @param {string} name the temporary file name
|
707
|
-
*/
|
708
|
-
|
709
|
-
/**
|
710
|
-
* @callback fileCallback
|
711
|
-
* @param {?Error} err the error object if anything goes wrong
|
712
|
-
* @param {string} name the temporary file name
|
713
|
-
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
714
|
-
* @param {cleanupCallback} fn the cleanup callback function
|
715
|
-
*/
|
716
|
-
|
717
|
-
/**
|
718
|
-
* @callback fileCallbackSync
|
719
|
-
* @param {?Error} err the error object if anything goes wrong
|
720
|
-
* @param {string} name the temporary file name
|
721
|
-
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
722
|
-
* @param {cleanupCallbackSync} fn the cleanup callback function
|
723
|
-
*/
|
724
|
-
|
725
|
-
/**
|
726
|
-
* @callback dirCallback
|
727
|
-
* @param {?Error} err the error object if anything goes wrong
|
728
|
-
* @param {string} name the temporary file name
|
729
|
-
* @param {cleanupCallback} fn the cleanup callback function
|
730
|
-
*/
|
731
|
-
|
732
|
-
/**
|
733
|
-
* @callback dirCallbackSync
|
734
|
-
* @param {?Error} err the error object if anything goes wrong
|
735
|
-
* @param {string} name the temporary file name
|
736
|
-
* @param {cleanupCallbackSync} fn the cleanup callback function
|
737
|
-
*/
|
738
|
-
|
739
|
-
/**
|
740
|
-
* Removes the temporary created file or directory.
|
741
|
-
*
|
742
|
-
* @callback cleanupCallback
|
743
|
-
* @param {simpleCallback} [next] function to call whenever the tmp object needs to be removed
|
744
|
-
*/
|
745
|
-
|
746
|
-
/**
|
747
|
-
* Removes the temporary created file or directory.
|
748
|
-
*
|
749
|
-
* @callback cleanupCallbackSync
|
750
|
-
*/
|
751
|
-
|
752
|
-
/**
|
753
|
-
* Callback function for function composition.
|
754
|
-
* @see {@link https://github.com/raszi/node-tmp/issues/57|raszi/node-tmp#57}
|
755
|
-
*
|
756
|
-
* @callback simpleCallback
|
757
|
-
*/
|
758
|
-
|
759
|
-
// exporting all the needed methods
|
760
|
-
|
761
|
-
// evaluate _getTmpDir() lazily, mainly for simplifying testing but it also will
|
762
|
-
// allow users to reconfigure the temporary directory
|
763
|
-
Object.defineProperty(module.exports, 'tmpdir', {
|
764
|
-
enumerable: true,
|
765
|
-
configurable: false,
|
766
|
-
get: function () {
|
767
|
-
return _getTmpDir();
|
768
|
-
}
|
769
|
-
});
|
770
|
-
|
771
|
-
module.exports.dir = dir;
|
772
|
-
module.exports.dirSync = dirSync;
|
773
|
-
|
774
|
-
module.exports.file = file;
|
775
|
-
module.exports.fileSync = fileSync;
|
776
|
-
|
777
|
-
module.exports.tmpName = tmpName;
|
778
|
-
module.exports.tmpNameSync = tmpNameSync;
|
779
|
-
|
780
|
-
module.exports.setGracefulCleanup = setGracefulCleanup;
|