├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── examples ├── grepcount.js └── pdfcreator.js ├── lib └── temp.js ├── media └── A5.jpg ├── package-lock.json ├── package.json └── test └── temp-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .\#* 3 | /node_modules 4 | \#* 5 | npm-debug.log 6 | node_modules 7 | *.tgz 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "lts/*" 5 | - "6" 6 | - "7" 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010-2014 Bruce Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Image of node-temp logo](https://raw.githubusercontent.com/bruce/node-temp/master/media/A5.jpg) 2 | ========= 3 | 4 | Temporary files, directories, and streams for Node.js. 5 | 6 | Handles generating a unique file/directory name under the appropriate 7 | system temporary directory, changing the file to an appropriate mode, 8 | and supports automatic removal (if asked) 9 | 10 | `temp` has a similar API to the `fs` module. 11 | 12 | Node.js Compatibility 13 | --------------------- 14 | 15 | Supports v6.0.0+. 16 | 17 | [![Build Status](https://travis-ci.org/bruce/node-temp.png)](https://travis-ci.org/bruce/node-temp) 18 | 19 | Please let me know if you have problems running it on a later version of Node.js or 20 | have platform-specific problems. 21 | 22 | Installation 23 | ------------ 24 | 25 | Install it using [npm](http://github.com/isaacs/npm): 26 | 27 | $ npm install temp 28 | 29 | Or get it directly from: 30 | http://github.com/bruce/node-temp 31 | 32 | Synopsis 33 | -------- 34 | 35 | You can create temporary files with `open` and `openSync`, temporary 36 | directories with `mkdir` and `mkdirSync`, or you can get a unique name 37 | in the system temporary directory with `path`. 38 | 39 | See the [API section](https://github.com/bruce/node-temp#API) for more details on the API of `temp`. 40 | 41 | Working copies of the following examples can be found under the 42 | `examples` directory. 43 | 44 | ### Temporary Files (`open` and `openSync`) 45 | 46 | To create a temporary file use `open` or `openSync`, passing 47 | them an optional prefix, suffix, or both (see below for details on 48 | affixes). The object passed to the callback (or returned) has 49 | `path` and `fd` keys: 50 | 51 | ```javascript 52 | { path: "/path/to/file", 53 | , fd: theFileDescriptor 54 | } 55 | ``` 56 | 57 | In this example we write to a temporary file and call out to `grep` and 58 | `wc -l` to determine the number of time `foo` occurs in the text. The 59 | temporary file is chmod'd `0600` and cleaned up automatically when the 60 | process at exit (because `temp.track()` is called): 61 | 62 | ```javascript 63 | var temp = require('temp'), 64 | fs = require('fs'), 65 | util = require('util'), 66 | exec = require('child_process').exec; 67 | 68 | // Automatically track and cleanup files at exit 69 | temp.track(); 70 | 71 | // Fake data 72 | var myData = "foo\nbar\nfoo\nbaz"; 73 | 74 | // Process the data (note: error handling omitted) 75 | temp.open('myprefix', function(err, info) { 76 | if (!err) { 77 | fs.write(info.fd, myData, (err) => { 78 | console.log(err); 79 | }); 80 | fs.close(info.fd, function(err) { 81 | exec("grep foo '" + info.path + "' | wc -l", function(err, stdout) { 82 | util.puts(stdout.trim()); 83 | }); 84 | }); 85 | } 86 | }); 87 | ``` 88 | 89 | ### Want Cleanup? Make sure you ask for it. (`track`) 90 | 91 | As noted in the example above, if you want temp to track the files and 92 | directories it creates and handle removing those files and directories 93 | on exit, you must call `track()`. The `track()` function is chainable, 94 | and it's recommended that you call it when requiring the module. 95 | 96 | ```javascript 97 | var temp = require("temp").track(); 98 | ``` 99 | 100 | Why is this necessary? In pre-0.6 versions of temp, tracking was 101 | automatic. While this works great for scripts and 102 | [Grunt tasks](http://gruntjs.com/), it's not so great for long-running 103 | server processes. Since that's arguably what Node.js is _for_, you 104 | have to opt-in to tracking. 105 | 106 | But it's easy. 107 | 108 | #### Cleanup anytime (`cleanup`, `cleanupSync`) 109 | 110 | When tracking, you can run `cleanup()` and `cleanupSync()` anytime 111 | (`cleanupSync()` will be run for you on process exit). An object will 112 | be returned (or passed to the callback) with cleanup counts and 113 | the file/directory tracking lists will be reset. 114 | 115 | ```javascript 116 | > temp.cleanupSync(); 117 | { files: 1, 118 | dirs: 0 } 119 | ``` 120 | 121 | ```javascript 122 | > temp.cleanup(function(err, stats) { 123 | console.log(stats); 124 | }); 125 | { files: 1, 126 | dirs: 0 } 127 | ``` 128 | 129 | Note: If you're not tracking, an error ("not tracking") will be passed 130 | to the callback. 131 | 132 | ### Temporary Directories (`mkdir`, `mkdirSync`) 133 | 134 | To create a temporary directory, use `mkdir` or `mkdirSync`, passing 135 | it an optional prefix, suffix, or both (see below for details on affixes). 136 | 137 | In this example we create a temporary directory, write to a file 138 | within it, call out to an external program to create a PDF, and read 139 | the result. While the external process creates a lot of additional 140 | files, the temporary directory is removed automatically at exit (because 141 | `temp.track()` is called): 142 | 143 | ```javascript 144 | var temp = require('temp'), 145 | fs = require('fs'), 146 | util = require('util'), 147 | path = require('path'), 148 | exec = require('child_process').exec; 149 | 150 | // Automatically track and cleanup files at exit 151 | temp.track(); 152 | 153 | // For use with ConTeXt, http://wiki.contextgarden.net 154 | var myData = "\\starttext\nHello World\n\\stoptext"; 155 | 156 | temp.mkdir('pdfcreator', function(err, dirPath) { 157 | var inputPath = path.join(dirPath, 'input.tex') 158 | fs.writeFile(inputPath, myData, function(err) { 159 | if (err) throw err; 160 | process.chdir(dirPath); 161 | exec("texexec '" + inputPath + "'", function(err) { 162 | if (err) throw err; 163 | fs.readFile(path.join(dirPath, 'input.pdf'), function(err, data) { 164 | if (err) throw err; 165 | sys.print(data); 166 | }); 167 | }); 168 | }); 169 | }); 170 | ``` 171 | 172 | ### Temporary Streams (`createWriteStream`) 173 | 174 | To create a temporary WriteStream, use 'createWriteStream', which sits 175 | on top of `fs.createWriteStream`. The return value is a 176 | `fs.WriteStream` with a `path` property containing the temporary file 177 | path for the stream. The `path` is registered for removal when 178 | `temp.cleanup` is called (because `temp.track()` is called). 179 | 180 | ```javascript 181 | var temp = require('temp'); 182 | 183 | // Automatically track and cleanup files at exit 184 | temp.track(); 185 | 186 | var stream = temp.createWriteStream(); 187 | // stream.path contains the temporary file path for the stream 188 | stream.write("Some data"); 189 | // Maybe do some other things 190 | stream.end(); 191 | ``` 192 | 193 | ### Affixes (options) 194 | 195 | You can provide custom prefixes and suffixes when creating temporary 196 | files and directories. If you provide a string, it is used as the prefix 197 | for the temporary name. If you provide an object with `prefix`, 198 | `suffix` and `dir` keys, they are used for the temporary name. 199 | 200 | Here are some examples: 201 | 202 | * `"aprefix"`: A simple prefix, prepended to the filename; this is 203 | shorthand for: 204 | * `{prefix: "aprefix"}`: A simple prefix, prepended to the filename 205 | * `{suffix: ".asuffix"}`: A suffix, appended to the filename 206 | (especially useful when the file needs to be named with specific 207 | extension for use with an external program). 208 | * `{prefix: "myprefix", suffix: "mysuffix"}`: Customize both affixes 209 | * `{dir: path.join(os.tmpdir(), "myapp")}`: default prefix and suffix 210 | within a new temporary directory. 211 | * `null`: Use the defaults for files and directories (prefixes `"f-"` 212 | and `"d-"`, respectively, no suffixes). 213 | 214 | In this simple example we read a `pdf`, write it to a temporary file with 215 | a `.pdf` extension, and close it. 216 | 217 | ```javascript 218 | var fs = require('fs'), 219 | temp = require('temp'); 220 | 221 | fs.readFile('/path/to/source.pdf', function(err, data) { 222 | temp.open({suffix: '.pdf'}, function(err, info) { 223 | if (err) throw err; 224 | fs.write(info.fd, data, (err) => { 225 | console.log(err) 226 | }); 227 | fs.close(info.fd, function(err) { 228 | if (err) throw err; 229 | // Do something with the file 230 | }); 231 | }); 232 | }); 233 | ``` 234 | 235 | ### Just a path, please (`path`) 236 | 237 | If you just want a unique name in your temporary directory, use 238 | `path`: 239 | 240 | ```javascript 241 | var fs = require('fs'); 242 | var tempName = temp.path({suffix: '.pdf'}); 243 | // Do something with tempName 244 | ``` 245 | 246 | Note: The file isn't created for you, and the mode is not changed -- and it 247 | will not be removed automatically at exit. If you use `path`, it's 248 | all up to you. 249 | 250 | 251 | API 252 | ------- 253 | 254 | ```ts 255 | interface OpenFile { 256 | path: string; 257 | fd: number; 258 | } 259 | 260 | interface Stats { 261 | files: number; 262 | dirs: number; 263 | } 264 | 265 | interface AffixOptions { 266 | prefix?: string; 267 | suffix?: string; 268 | dir?: string; 269 | } 270 | 271 | function track(value?: boolean): typeof temp; 272 | 273 | function mkdir(affixes: string | AffixOptions | undefined, callback: (err: any, dirPath: string) => void): void; 274 | function mkdir(affixes?: string | AffixOptions): Promise; 275 | 276 | function mkdirSync(affixes?: string | AffixOptions): string; 277 | 278 | function open(affixes: string | AffixOptions | undefined, callback: (err: any, result: OpenFile) => void): void; 279 | function open(affixes?: string | AffixOptions): Promise; 280 | 281 | function openSync(affixes?: string | AffixOptions): OpenFile; 282 | 283 | function path(affixes?: string | AffixOptions, defaultPrefix?: string): string; 284 | 285 | function cleanup(callback: (err: any, result: Stats) => void): void; 286 | function cleanup(): Promise; 287 | 288 | function cleanupSync(): boolean | Stats; 289 | 290 | function createWriteStream(affixes?: string | AffixOptions): fs.WriteStream; 291 | ``` 292 | 293 | 294 | Testing 295 | ------- 296 | 297 | ```sh 298 | $ npm test 299 | ``` 300 | 301 | Contributing 302 | ------------ 303 | 304 | You can find the repository at: 305 | http://github.com/bruce/node-temp 306 | 307 | Issues/Feature Requests can be submitted at: 308 | http://github.com/bruce/node-temp/issues 309 | 310 | I'd really like to hear your feedback, and I'd love to receive your 311 | pull-requests! 312 | 313 | Copyright 314 | --------- 315 | 316 | Copyright (c) 2010-2014 Bruce Williams. This software is licensed 317 | under the MIT License, see LICENSE for details. 318 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Test against the latest version of this Node.js version 2 | environment: 3 | matrix: 4 | # node.js 5 | - nodejs_version: "stable" 6 | - nodejs_version: "lts" 7 | - nodejs_version: "6" 8 | - nodejs_version: "7" 9 | 10 | # Install scripts. (runs after repo cloning) 11 | install: 12 | # Get the latest stable version of Node.js or io.js 13 | - ps: Install-Product node $env:nodejs_version 14 | # install modules 15 | - npm install 16 | 17 | # Post-install test scripts. 18 | test_script: 19 | # Output useful info for debugging. 20 | - node --version 21 | - npm --version 22 | # run tests 23 | - npm test 24 | 25 | # Don't actually build. 26 | build: off 27 | -------------------------------------------------------------------------------- /examples/grepcount.js: -------------------------------------------------------------------------------- 1 | var temp = require('../lib/temp'), 2 | fs = require('fs'), 3 | util = require('util'), 4 | exec = require('child_process').exec; 5 | 6 | var myData = "foo\nbar\nfoo\nbaz"; 7 | 8 | temp.open('myprefix', function(err, info) { 9 | if (err) throw err; 10 | fs.write(info.fd, myData, function(err) { 11 | if (err) throw err; 12 | fs.close(info.fd, function(err) { 13 | if (err) throw err; 14 | exec("grep foo '" + info.path + "' | wc -l", function(err, stdout) { 15 | if (err) throw err; 16 | util.puts(stdout.trim()); 17 | }); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /examples/pdfcreator.js: -------------------------------------------------------------------------------- 1 | var temp = require('../lib/temp'), 2 | fs = require('fs'), 3 | util = require('util'), 4 | path = require('path'), 5 | exec = require('child_process').exec; 6 | 7 | var myData = "\\starttext\nHello World\n\\stoptext"; 8 | 9 | temp.mkdir('pdfcreator', function(err, dirPath) { 10 | var inputPath = path.join(dirPath, 'input.tex') 11 | fs.writeFile(inputPath, myData, function(err) { 12 | if (err) throw err; 13 | process.chdir(dirPath); 14 | exec("texexec '" + inputPath + "'", function(err) { 15 | if (err) throw err; 16 | fs.readFile(path.join(dirPath, 'input.pdf'), function(err, data) { 17 | if (err) throw err; 18 | util.print(data); 19 | }); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /lib/temp.js: -------------------------------------------------------------------------------- 1 | let fs = require('fs'); 2 | let path = require('path'); 3 | let cnst = require('constants'); 4 | 5 | let os = require('os'); 6 | let rimraf = require('rimraf'); 7 | let mkdirp = require('mkdirp'); 8 | let osTmpdir = require('os').tmpdir(); 9 | 10 | const rimrafSync = rimraf.sync; 11 | 12 | //== helpers 13 | // 14 | let dir = path.resolve(os.tmpdir()); 15 | 16 | let RDWR_EXCL = cnst.O_CREAT | cnst.O_TRUNC | cnst.O_RDWR | cnst.O_EXCL; 17 | 18 | let promisify = function(callback) { 19 | if (typeof callback === 'function') { 20 | return [undefined, callback]; 21 | } 22 | 23 | var promiseCallback; 24 | var promise = new Promise(function(resolve, reject) { 25 | promiseCallback = function() { 26 | var args = Array.from(arguments); 27 | var err = args.shift(); 28 | 29 | process.nextTick(function() { 30 | if (err) { 31 | reject(err); 32 | } else if (args.length === 1) { 33 | resolve(args[0]); 34 | } else { 35 | resolve(args); 36 | } 37 | }); 38 | }; 39 | }); 40 | 41 | return [promise, promiseCallback]; 42 | }; 43 | 44 | var generateName = function(rawAffixes, defaultPrefix) { 45 | var affixes = parseAffixes(rawAffixes, defaultPrefix); 46 | var now = new Date(); 47 | var name = [affixes.prefix, 48 | now.getFullYear(), now.getMonth(), now.getDate(), 49 | '-', 50 | process.pid, 51 | '-', 52 | (Math.random() * 0x100000000 + 1).toString(36), 53 | affixes.suffix].join(''); 54 | return path.join(affixes.dir || dir, name); 55 | }; 56 | 57 | var parseAffixes = function(rawAffixes, defaultPrefix) { 58 | var affixes = {prefix: null, suffix: null}; 59 | if(rawAffixes) { 60 | switch (typeof(rawAffixes)) { 61 | case 'string': 62 | affixes.prefix = rawAffixes; 63 | break; 64 | case 'object': 65 | affixes = rawAffixes; 66 | break; 67 | default: 68 | throw new Error("Unknown affix declaration: " + affixes); 69 | } 70 | } else { 71 | affixes.prefix = defaultPrefix; 72 | } 73 | return affixes; 74 | }; 75 | 76 | /* ------------------------------------------------------------------------- 77 | * Don't forget to call track() if you want file tracking and exit handlers! 78 | * ------------------------------------------------------------------------- 79 | * When any temp file or directory is created, it is added to filesToDelete 80 | * or dirsToDelete. The first time any temp file is created, a listener is 81 | * added to remove all temp files and directories at exit. 82 | */ 83 | var tracking = false; 84 | var track = function(value) { 85 | tracking = (value !== false); 86 | return module.exports; // chainable 87 | }; 88 | var exitListenerAttached = false; 89 | var filesToDelete = []; 90 | var dirsToDelete = []; 91 | 92 | function deleteFileOnExit(filePath) { 93 | if (!tracking) return false; 94 | attachExitListener(); 95 | filesToDelete.push(filePath); 96 | } 97 | 98 | function deleteDirOnExit(dirPath) { 99 | if (!tracking) return false; 100 | attachExitListener(); 101 | dirsToDelete.push(dirPath); 102 | } 103 | 104 | function attachExitListener() { 105 | if (!tracking) return false; 106 | if (!exitListenerAttached) { 107 | process.addListener('exit', function() { 108 | try { 109 | cleanupSync(); 110 | } catch(err) { 111 | console.warn("Fail to clean temporary files on exit : ", err); 112 | throw err; 113 | } 114 | }); 115 | exitListenerAttached = true; 116 | } 117 | } 118 | 119 | function cleanupFilesSync() { 120 | if (!tracking) { 121 | return false; 122 | } 123 | var count = 0; 124 | var toDelete; 125 | while ((toDelete = filesToDelete.shift()) !== undefined) { 126 | rimrafSync(toDelete, { maxBusyTries: 6 }); 127 | count++; 128 | } 129 | return count; 130 | } 131 | 132 | function cleanupFiles(callback) { 133 | var p = promisify(callback); 134 | var promise = p[0]; 135 | callback = p[1]; 136 | 137 | if (!tracking) { 138 | callback(new Error("not tracking")); 139 | return promise; 140 | } 141 | var count = 0; 142 | var left = filesToDelete.length; 143 | if (!left) { 144 | callback(null, count); 145 | return promise; 146 | } 147 | var toDelete; 148 | var rimrafCallback = function(err) { 149 | if (!left) { 150 | // Prevent processing if aborted 151 | return; 152 | } 153 | if (err) { 154 | // This shouldn't happen; pass error to callback and abort 155 | // processing 156 | callback(err); 157 | left = 0; 158 | return; 159 | } else { 160 | count++; 161 | } 162 | left--; 163 | if (!left) { 164 | callback(null, count); 165 | } 166 | }; 167 | while ((toDelete = filesToDelete.shift()) !== undefined) { 168 | rimraf(toDelete, { maxBusyTries: 6 }, rimrafCallback); 169 | } 170 | return promise; 171 | } 172 | 173 | function cleanupDirsSync() { 174 | if (!tracking) { 175 | return false; 176 | } 177 | var count = 0; 178 | var toDelete; 179 | while ((toDelete = dirsToDelete.shift()) !== undefined) { 180 | rimrafSync(toDelete, { maxBusyTries: 6 }); 181 | count++; 182 | } 183 | return count; 184 | } 185 | 186 | function cleanupDirs(callback) { 187 | var p = promisify(callback); 188 | var promise = p[0]; 189 | callback = p[1]; 190 | 191 | if (!tracking) { 192 | callback(new Error("not tracking")); 193 | return promise; 194 | } 195 | var count = 0; 196 | var left = dirsToDelete.length; 197 | if (!left) { 198 | callback(null, count); 199 | return promise; 200 | } 201 | var toDelete; 202 | var rimrafCallback = function (err) { 203 | if (!left) { 204 | // Prevent processing if aborted 205 | return; 206 | } 207 | if (err) { 208 | // rimraf handles most "normal" errors; pass the error to the 209 | // callback and abort processing 210 | callback(err, count); 211 | left = 0; 212 | return; 213 | } else { 214 | count++; 215 | } 216 | left--; 217 | if (!left) { 218 | callback(null, count); 219 | } 220 | }; 221 | while ((toDelete = dirsToDelete.shift()) !== undefined) { 222 | rimraf(toDelete, { maxBusyTries: 6 }, rimrafCallback); 223 | } 224 | return promise; 225 | } 226 | 227 | function cleanupSync() { 228 | if (!tracking) { 229 | return false; 230 | } 231 | var fileCount = cleanupFilesSync(); 232 | var dirCount = cleanupDirsSync(); 233 | return {files: fileCount, dirs: dirCount}; 234 | } 235 | 236 | function cleanup(callback) { 237 | var p = promisify(callback); 238 | var promise = p[0]; 239 | callback = p[1]; 240 | 241 | if (!tracking) { 242 | callback(new Error("not tracking")); 243 | return promise; 244 | } 245 | cleanupFiles(function(fileErr, fileCount) { 246 | if (fileErr) { 247 | callback(fileErr, {files: fileCount}); 248 | } else { 249 | cleanupDirs(function(dirErr, dirCount) { 250 | callback(dirErr, {files: fileCount, dirs: dirCount}); 251 | }); 252 | } 253 | }); 254 | return promise; 255 | } 256 | 257 | //== directories 258 | // 259 | const mkdir = (affixes, callback) => { 260 | const p = promisify(callback); 261 | const promise = p[0]; 262 | callback = p[1]; 263 | 264 | let dirPath = generateName(affixes, 'd-'); 265 | mkdirp(dirPath, 0o700, (err) => { 266 | if (!err) { 267 | deleteDirOnExit(dirPath); 268 | } 269 | callback(err, dirPath); 270 | }); 271 | return promise; 272 | } 273 | 274 | const mkdirSync = (affixes) => { 275 | let dirPath = generateName(affixes, 'd-'); 276 | mkdirp.sync(dirPath, 0o700); 277 | deleteDirOnExit(dirPath); 278 | return dirPath; 279 | } 280 | 281 | //== files 282 | // 283 | const open = (affixes, callback) => { 284 | const p = promisify(callback); 285 | const promise = p[0]; 286 | callback = p[1]; 287 | 288 | const path = generateName(affixes, 'f-'); 289 | fs.open(path, RDWR_EXCL, 0o600, (err, fd) => { 290 | if (!err) { 291 | deleteFileOnExit(path); 292 | } 293 | callback(err, { path, fd }); 294 | }); 295 | return promise; 296 | } 297 | 298 | const openSync = (affixes) => { 299 | const path = generateName(affixes, 'f-'); 300 | let fd = fs.openSync(path, RDWR_EXCL, 0o600); 301 | deleteFileOnExit(path); 302 | return { path, fd }; 303 | } 304 | 305 | const createWriteStream = (affixes) => { 306 | const path = generateName(affixes, 's-'); 307 | let stream = fs.createWriteStream(path, { flags: RDWR_EXCL, mode: 0o600 }); 308 | deleteFileOnExit(path); 309 | return stream; 310 | } 311 | 312 | //== settings 313 | // 314 | exports.dir = dir; 315 | exports.track = track; 316 | 317 | //== functions 318 | // 319 | exports.mkdir = mkdir; 320 | exports.mkdirSync = mkdirSync; 321 | exports.open = open; 322 | exports.openSync = openSync; 323 | exports.path = generateName; 324 | exports.cleanup = cleanup; 325 | exports.cleanupSync = cleanupSync; 326 | exports.createWriteStream = createWriteStream; 327 | -------------------------------------------------------------------------------- /media/A5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bruce/node-temp/3b30821fe071d64ae239db7b09ea056f5175c834/media/A5.jpg -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "temp", 3 | "version": "0.9.4", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "ansi-colors": { 8 | "version": "3.2.3", 9 | "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", 10 | "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", 11 | "dev": true 12 | }, 13 | "ansi-regex": { 14 | "version": "3.0.0", 15 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", 16 | "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", 17 | "dev": true 18 | }, 19 | "ansi-styles": { 20 | "version": "3.2.1", 21 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", 22 | "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", 23 | "dev": true, 24 | "requires": { 25 | "color-convert": "^1.9.0" 26 | } 27 | }, 28 | "argparse": { 29 | "version": "1.0.10", 30 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", 31 | "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", 32 | "dev": true, 33 | "requires": { 34 | "sprintf-js": "~1.0.2" 35 | } 36 | }, 37 | "balanced-match": { 38 | "version": "1.0.0", 39 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 40 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 41 | }, 42 | "brace-expansion": { 43 | "version": "1.1.11", 44 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 45 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 46 | "requires": { 47 | "balanced-match": "^1.0.0", 48 | "concat-map": "0.0.1" 49 | } 50 | }, 51 | "browser-stdout": { 52 | "version": "1.3.1", 53 | "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", 54 | "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", 55 | "dev": true 56 | }, 57 | "camelcase": { 58 | "version": "5.3.1", 59 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", 60 | "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", 61 | "dev": true 62 | }, 63 | "chalk": { 64 | "version": "2.4.2", 65 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", 66 | "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", 67 | "dev": true, 68 | "requires": { 69 | "ansi-styles": "^3.2.1", 70 | "escape-string-regexp": "^1.0.5", 71 | "supports-color": "^5.3.0" 72 | }, 73 | "dependencies": { 74 | "supports-color": { 75 | "version": "5.5.0", 76 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", 77 | "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", 78 | "dev": true, 79 | "requires": { 80 | "has-flag": "^3.0.0" 81 | } 82 | } 83 | } 84 | }, 85 | "cliui": { 86 | "version": "5.0.0", 87 | "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", 88 | "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", 89 | "dev": true, 90 | "requires": { 91 | "string-width": "^3.1.0", 92 | "strip-ansi": "^5.2.0", 93 | "wrap-ansi": "^5.1.0" 94 | }, 95 | "dependencies": { 96 | "ansi-regex": { 97 | "version": "4.1.0", 98 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", 99 | "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", 100 | "dev": true 101 | }, 102 | "string-width": { 103 | "version": "3.1.0", 104 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", 105 | "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", 106 | "dev": true, 107 | "requires": { 108 | "emoji-regex": "^7.0.1", 109 | "is-fullwidth-code-point": "^2.0.0", 110 | "strip-ansi": "^5.1.0" 111 | } 112 | }, 113 | "strip-ansi": { 114 | "version": "5.2.0", 115 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", 116 | "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", 117 | "dev": true, 118 | "requires": { 119 | "ansi-regex": "^4.1.0" 120 | } 121 | } 122 | } 123 | }, 124 | "color-convert": { 125 | "version": "1.9.3", 126 | "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", 127 | "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", 128 | "dev": true, 129 | "requires": { 130 | "color-name": "1.1.3" 131 | } 132 | }, 133 | "color-name": { 134 | "version": "1.1.3", 135 | "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", 136 | "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", 137 | "dev": true 138 | }, 139 | "concat-map": { 140 | "version": "0.0.1", 141 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 142 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 143 | }, 144 | "debug": { 145 | "version": "3.2.6", 146 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", 147 | "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", 148 | "dev": true, 149 | "requires": { 150 | "ms": "^2.1.1" 151 | } 152 | }, 153 | "decamelize": { 154 | "version": "1.2.0", 155 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", 156 | "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", 157 | "dev": true 158 | }, 159 | "define-properties": { 160 | "version": "1.1.3", 161 | "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", 162 | "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", 163 | "dev": true, 164 | "requires": { 165 | "object-keys": "^1.0.12" 166 | } 167 | }, 168 | "diff": { 169 | "version": "3.5.0", 170 | "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", 171 | "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", 172 | "dev": true 173 | }, 174 | "emoji-regex": { 175 | "version": "7.0.3", 176 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", 177 | "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", 178 | "dev": true 179 | }, 180 | "es-abstract": { 181 | "version": "1.17.6", 182 | "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.6.tgz", 183 | "integrity": "sha512-Fr89bON3WFyUi5EvAeI48QTWX0AyekGgLA8H+c+7fbfCkJwRWRMLd8CQedNEyJuoYYhmtEqY92pgte1FAhBlhw==", 184 | "dev": true, 185 | "requires": { 186 | "es-to-primitive": "^1.2.1", 187 | "function-bind": "^1.1.1", 188 | "has": "^1.0.3", 189 | "has-symbols": "^1.0.1", 190 | "is-callable": "^1.2.0", 191 | "is-regex": "^1.1.0", 192 | "object-inspect": "^1.7.0", 193 | "object-keys": "^1.1.1", 194 | "object.assign": "^4.1.0", 195 | "string.prototype.trimend": "^1.0.1", 196 | "string.prototype.trimstart": "^1.0.1" 197 | } 198 | }, 199 | "es-to-primitive": { 200 | "version": "1.2.1", 201 | "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", 202 | "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", 203 | "dev": true, 204 | "requires": { 205 | "is-callable": "^1.1.4", 206 | "is-date-object": "^1.0.1", 207 | "is-symbol": "^1.0.2" 208 | } 209 | }, 210 | "escape-string-regexp": { 211 | "version": "1.0.5", 212 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 213 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 214 | "dev": true 215 | }, 216 | "esprima": { 217 | "version": "4.0.1", 218 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", 219 | "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", 220 | "dev": true 221 | }, 222 | "find-up": { 223 | "version": "3.0.0", 224 | "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", 225 | "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", 226 | "dev": true, 227 | "requires": { 228 | "locate-path": "^3.0.0" 229 | } 230 | }, 231 | "flat": { 232 | "version": "4.1.0", 233 | "resolved": "https://registry.npmjs.org/flat/-/flat-4.1.0.tgz", 234 | "integrity": "sha512-Px/TiLIznH7gEDlPXcUD4KnBusa6kR6ayRUVcnEAbreRIuhkqow/mun59BuRXwoYk7ZQOLW1ZM05ilIvK38hFw==", 235 | "dev": true, 236 | "requires": { 237 | "is-buffer": "~2.0.3" 238 | } 239 | }, 240 | "fs.realpath": { 241 | "version": "1.0.0", 242 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 243 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 244 | }, 245 | "function-bind": { 246 | "version": "1.1.1", 247 | "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", 248 | "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", 249 | "dev": true 250 | }, 251 | "get-caller-file": { 252 | "version": "2.0.5", 253 | "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", 254 | "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", 255 | "dev": true 256 | }, 257 | "glob": { 258 | "version": "7.1.3", 259 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", 260 | "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", 261 | "requires": { 262 | "fs.realpath": "^1.0.0", 263 | "inflight": "^1.0.4", 264 | "inherits": "2", 265 | "minimatch": "^3.0.4", 266 | "once": "^1.3.0", 267 | "path-is-absolute": "^1.0.0" 268 | } 269 | }, 270 | "growl": { 271 | "version": "1.10.5", 272 | "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", 273 | "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", 274 | "dev": true 275 | }, 276 | "has": { 277 | "version": "1.0.3", 278 | "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", 279 | "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", 280 | "dev": true, 281 | "requires": { 282 | "function-bind": "^1.1.1" 283 | } 284 | }, 285 | "has-flag": { 286 | "version": "3.0.0", 287 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", 288 | "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", 289 | "dev": true 290 | }, 291 | "has-symbols": { 292 | "version": "1.0.1", 293 | "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", 294 | "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==", 295 | "dev": true 296 | }, 297 | "he": { 298 | "version": "1.2.0", 299 | "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", 300 | "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", 301 | "dev": true 302 | }, 303 | "inflight": { 304 | "version": "1.0.6", 305 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 306 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 307 | "requires": { 308 | "once": "^1.3.0", 309 | "wrappy": "1" 310 | } 311 | }, 312 | "inherits": { 313 | "version": "2.0.3", 314 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 315 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 316 | }, 317 | "is-buffer": { 318 | "version": "2.0.4", 319 | "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", 320 | "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==", 321 | "dev": true 322 | }, 323 | "is-callable": { 324 | "version": "1.2.0", 325 | "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz", 326 | "integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==", 327 | "dev": true 328 | }, 329 | "is-date-object": { 330 | "version": "1.0.2", 331 | "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", 332 | "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==", 333 | "dev": true 334 | }, 335 | "is-fullwidth-code-point": { 336 | "version": "2.0.0", 337 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", 338 | "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", 339 | "dev": true 340 | }, 341 | "is-regex": { 342 | "version": "1.1.1", 343 | "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz", 344 | "integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==", 345 | "dev": true, 346 | "requires": { 347 | "has-symbols": "^1.0.1" 348 | } 349 | }, 350 | "is-symbol": { 351 | "version": "1.0.3", 352 | "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", 353 | "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", 354 | "dev": true, 355 | "requires": { 356 | "has-symbols": "^1.0.1" 357 | } 358 | }, 359 | "isexe": { 360 | "version": "2.0.0", 361 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", 362 | "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", 363 | "dev": true 364 | }, 365 | "js-yaml": { 366 | "version": "3.13.1", 367 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", 368 | "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", 369 | "dev": true, 370 | "requires": { 371 | "argparse": "^1.0.7", 372 | "esprima": "^4.0.0" 373 | } 374 | }, 375 | "locate-path": { 376 | "version": "3.0.0", 377 | "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", 378 | "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", 379 | "dev": true, 380 | "requires": { 381 | "p-locate": "^3.0.0", 382 | "path-exists": "^3.0.0" 383 | } 384 | }, 385 | "lodash": { 386 | "version": "4.17.20", 387 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", 388 | "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", 389 | "dev": true 390 | }, 391 | "log-symbols": { 392 | "version": "2.2.0", 393 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", 394 | "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", 395 | "dev": true, 396 | "requires": { 397 | "chalk": "^2.0.1" 398 | } 399 | }, 400 | "minimatch": { 401 | "version": "3.0.4", 402 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 403 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 404 | "requires": { 405 | "brace-expansion": "^1.1.7" 406 | } 407 | }, 408 | "minimist": { 409 | "version": "0.0.8", 410 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", 411 | "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" 412 | }, 413 | "mkdirp": { 414 | "version": "0.5.1", 415 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", 416 | "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", 417 | "requires": { 418 | "minimist": "0.0.8" 419 | } 420 | }, 421 | "mocha": { 422 | "version": "6.2.3", 423 | "resolved": "https://registry.npmjs.org/mocha/-/mocha-6.2.3.tgz", 424 | "integrity": "sha512-0R/3FvjIGH3eEuG17ccFPk117XL2rWxatr81a57D+r/x2uTYZRbdZ4oVidEUMh2W2TJDa7MdAb12Lm2/qrKajg==", 425 | "dev": true, 426 | "requires": { 427 | "ansi-colors": "3.2.3", 428 | "browser-stdout": "1.3.1", 429 | "debug": "3.2.6", 430 | "diff": "3.5.0", 431 | "escape-string-regexp": "1.0.5", 432 | "find-up": "3.0.0", 433 | "glob": "7.1.3", 434 | "growl": "1.10.5", 435 | "he": "1.2.0", 436 | "js-yaml": "3.13.1", 437 | "log-symbols": "2.2.0", 438 | "minimatch": "3.0.4", 439 | "mkdirp": "0.5.4", 440 | "ms": "2.1.1", 441 | "node-environment-flags": "1.0.5", 442 | "object.assign": "4.1.0", 443 | "strip-json-comments": "2.0.1", 444 | "supports-color": "6.0.0", 445 | "which": "1.3.1", 446 | "wide-align": "1.1.3", 447 | "yargs": "13.3.2", 448 | "yargs-parser": "13.1.2", 449 | "yargs-unparser": "1.6.0" 450 | }, 451 | "dependencies": { 452 | "minimist": { 453 | "version": "1.2.5", 454 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", 455 | "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", 456 | "dev": true 457 | }, 458 | "mkdirp": { 459 | "version": "0.5.4", 460 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.4.tgz", 461 | "integrity": "sha512-iG9AK/dJLtJ0XNgTuDbSyNS3zECqDlAhnQW4CsNxBG3LQJBbHmRX1egw39DmtOdCAqY+dKXV+sgPgilNWUKMVw==", 462 | "dev": true, 463 | "requires": { 464 | "minimist": "^1.2.5" 465 | } 466 | } 467 | } 468 | }, 469 | "ms": { 470 | "version": "2.1.1", 471 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 472 | "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", 473 | "dev": true 474 | }, 475 | "node-environment-flags": { 476 | "version": "1.0.5", 477 | "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.5.tgz", 478 | "integrity": "sha512-VNYPRfGfmZLx0Ye20jWzHUjyTW/c+6Wq+iLhDzUI4XmhrDd9l/FozXV3F2xOaXjvp0co0+v1YSR3CMP6g+VvLQ==", 479 | "dev": true, 480 | "requires": { 481 | "object.getownpropertydescriptors": "^2.0.3", 482 | "semver": "^5.7.0" 483 | } 484 | }, 485 | "object-inspect": { 486 | "version": "1.8.0", 487 | "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.8.0.tgz", 488 | "integrity": "sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA==", 489 | "dev": true 490 | }, 491 | "object-keys": { 492 | "version": "1.1.1", 493 | "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", 494 | "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", 495 | "dev": true 496 | }, 497 | "object.assign": { 498 | "version": "4.1.0", 499 | "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", 500 | "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", 501 | "dev": true, 502 | "requires": { 503 | "define-properties": "^1.1.2", 504 | "function-bind": "^1.1.1", 505 | "has-symbols": "^1.0.0", 506 | "object-keys": "^1.0.11" 507 | } 508 | }, 509 | "object.getownpropertydescriptors": { 510 | "version": "2.1.0", 511 | "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", 512 | "integrity": "sha512-Z53Oah9A3TdLoblT7VKJaTDdXdT+lQO+cNpKVnya5JDe9uLvzu1YyY1yFDFrcxrlRgWrEFH0jJtD/IbuwjcEVg==", 513 | "dev": true, 514 | "requires": { 515 | "define-properties": "^1.1.3", 516 | "es-abstract": "^1.17.0-next.1" 517 | } 518 | }, 519 | "once": { 520 | "version": "1.4.0", 521 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 522 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 523 | "requires": { 524 | "wrappy": "1" 525 | } 526 | }, 527 | "p-limit": { 528 | "version": "2.3.0", 529 | "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", 530 | "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", 531 | "dev": true, 532 | "requires": { 533 | "p-try": "^2.0.0" 534 | } 535 | }, 536 | "p-locate": { 537 | "version": "3.0.0", 538 | "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", 539 | "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", 540 | "dev": true, 541 | "requires": { 542 | "p-limit": "^2.0.0" 543 | } 544 | }, 545 | "p-try": { 546 | "version": "2.2.0", 547 | "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", 548 | "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", 549 | "dev": true 550 | }, 551 | "path-exists": { 552 | "version": "3.0.0", 553 | "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", 554 | "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", 555 | "dev": true 556 | }, 557 | "path-is-absolute": { 558 | "version": "1.0.1", 559 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 560 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 561 | }, 562 | "require-directory": { 563 | "version": "2.1.1", 564 | "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", 565 | "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", 566 | "dev": true 567 | }, 568 | "require-main-filename": { 569 | "version": "2.0.0", 570 | "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", 571 | "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", 572 | "dev": true 573 | }, 574 | "rimraf": { 575 | "version": "2.6.2", 576 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", 577 | "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", 578 | "requires": { 579 | "glob": "^7.0.5" 580 | } 581 | }, 582 | "semver": { 583 | "version": "5.7.1", 584 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", 585 | "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", 586 | "dev": true 587 | }, 588 | "set-blocking": { 589 | "version": "2.0.0", 590 | "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", 591 | "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", 592 | "dev": true 593 | }, 594 | "sprintf-js": { 595 | "version": "1.0.3", 596 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", 597 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", 598 | "dev": true 599 | }, 600 | "string-width": { 601 | "version": "2.1.1", 602 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", 603 | "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", 604 | "dev": true, 605 | "requires": { 606 | "is-fullwidth-code-point": "^2.0.0", 607 | "strip-ansi": "^4.0.0" 608 | } 609 | }, 610 | "string.prototype.trimend": { 611 | "version": "1.0.1", 612 | "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.1.tgz", 613 | "integrity": "sha512-LRPxFUaTtpqYsTeNKaFOw3R4bxIzWOnbQ837QfBylo8jIxtcbK/A/sMV7Q+OAV/vWo+7s25pOE10KYSjaSO06g==", 614 | "dev": true, 615 | "requires": { 616 | "define-properties": "^1.1.3", 617 | "es-abstract": "^1.17.5" 618 | } 619 | }, 620 | "string.prototype.trimstart": { 621 | "version": "1.0.1", 622 | "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.1.tgz", 623 | "integrity": "sha512-XxZn+QpvrBI1FOcg6dIpxUPgWCPuNXvMD72aaRaUQv1eD4e/Qy8i/hFTe0BUmD60p/QA6bh1avmuPTfNjqVWRw==", 624 | "dev": true, 625 | "requires": { 626 | "define-properties": "^1.1.3", 627 | "es-abstract": "^1.17.5" 628 | } 629 | }, 630 | "strip-ansi": { 631 | "version": "4.0.0", 632 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", 633 | "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", 634 | "dev": true, 635 | "requires": { 636 | "ansi-regex": "^3.0.0" 637 | } 638 | }, 639 | "strip-json-comments": { 640 | "version": "2.0.1", 641 | "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", 642 | "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", 643 | "dev": true 644 | }, 645 | "supports-color": { 646 | "version": "6.0.0", 647 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", 648 | "integrity": "sha512-on9Kwidc1IUQo+bQdhi8+Tijpo0e1SS6RoGo2guUwn5vdaxw8RXOF9Vb2ws+ihWOmh4JnCJOvaziZWP1VABaLg==", 649 | "dev": true, 650 | "requires": { 651 | "has-flag": "^3.0.0" 652 | } 653 | }, 654 | "which": { 655 | "version": "1.3.1", 656 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", 657 | "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", 658 | "dev": true, 659 | "requires": { 660 | "isexe": "^2.0.0" 661 | } 662 | }, 663 | "which-module": { 664 | "version": "2.0.0", 665 | "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", 666 | "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", 667 | "dev": true 668 | }, 669 | "wide-align": { 670 | "version": "1.1.3", 671 | "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", 672 | "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", 673 | "dev": true, 674 | "requires": { 675 | "string-width": "^1.0.2 || 2" 676 | } 677 | }, 678 | "wrap-ansi": { 679 | "version": "5.1.0", 680 | "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", 681 | "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", 682 | "dev": true, 683 | "requires": { 684 | "ansi-styles": "^3.2.0", 685 | "string-width": "^3.0.0", 686 | "strip-ansi": "^5.0.0" 687 | }, 688 | "dependencies": { 689 | "ansi-regex": { 690 | "version": "4.1.0", 691 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", 692 | "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", 693 | "dev": true 694 | }, 695 | "string-width": { 696 | "version": "3.1.0", 697 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", 698 | "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", 699 | "dev": true, 700 | "requires": { 701 | "emoji-regex": "^7.0.1", 702 | "is-fullwidth-code-point": "^2.0.0", 703 | "strip-ansi": "^5.1.0" 704 | } 705 | }, 706 | "strip-ansi": { 707 | "version": "5.2.0", 708 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", 709 | "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", 710 | "dev": true, 711 | "requires": { 712 | "ansi-regex": "^4.1.0" 713 | } 714 | } 715 | } 716 | }, 717 | "wrappy": { 718 | "version": "1.0.2", 719 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 720 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 721 | }, 722 | "y18n": { 723 | "version": "4.0.1", 724 | "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", 725 | "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", 726 | "dev": true 727 | }, 728 | "yargs": { 729 | "version": "13.3.2", 730 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", 731 | "integrity": "sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw==", 732 | "dev": true, 733 | "requires": { 734 | "cliui": "^5.0.0", 735 | "find-up": "^3.0.0", 736 | "get-caller-file": "^2.0.1", 737 | "require-directory": "^2.1.1", 738 | "require-main-filename": "^2.0.0", 739 | "set-blocking": "^2.0.0", 740 | "string-width": "^3.0.0", 741 | "which-module": "^2.0.0", 742 | "y18n": "^4.0.0", 743 | "yargs-parser": "^13.1.2" 744 | }, 745 | "dependencies": { 746 | "ansi-regex": { 747 | "version": "4.1.0", 748 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", 749 | "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", 750 | "dev": true 751 | }, 752 | "string-width": { 753 | "version": "3.1.0", 754 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", 755 | "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", 756 | "dev": true, 757 | "requires": { 758 | "emoji-regex": "^7.0.1", 759 | "is-fullwidth-code-point": "^2.0.0", 760 | "strip-ansi": "^5.1.0" 761 | } 762 | }, 763 | "strip-ansi": { 764 | "version": "5.2.0", 765 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", 766 | "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", 767 | "dev": true, 768 | "requires": { 769 | "ansi-regex": "^4.1.0" 770 | } 771 | } 772 | } 773 | }, 774 | "yargs-parser": { 775 | "version": "13.1.2", 776 | "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.2.tgz", 777 | "integrity": "sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg==", 778 | "dev": true, 779 | "requires": { 780 | "camelcase": "^5.0.0", 781 | "decamelize": "^1.2.0" 782 | } 783 | }, 784 | "yargs-unparser": { 785 | "version": "1.6.0", 786 | "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.6.0.tgz", 787 | "integrity": "sha512-W9tKgmSn0DpSatfri0nx52Joq5hVXgeLiqR/5G0sZNDoLZFOr/xjBUDcShCOGNsBnEMNo1KAMBkTej1Hm62HTw==", 788 | "dev": true, 789 | "requires": { 790 | "flat": "^4.1.0", 791 | "lodash": "^4.17.15", 792 | "yargs": "^13.3.0" 793 | } 794 | } 795 | } 796 | } 797 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "temp", 3 | "description": "Temporary files and directories", 4 | "tags": [ 5 | "temporary", 6 | "temp", 7 | "tempfile", 8 | "tempdir", 9 | "tmpfile", 10 | "tmpdir", 11 | "security" 12 | ], 13 | "version": "0.9.4", 14 | "author": "Bruce Williams ", 15 | "license": "MIT", 16 | "directories": { 17 | "lib": "lib" 18 | }, 19 | "engines": { 20 | "node": ">=6.0.0" 21 | }, 22 | "main": "./lib/temp", 23 | "dependencies": { 24 | "rimraf": "~2.6.2", 25 | "mkdirp": "^0.5.1" 26 | }, 27 | "keywords": [ 28 | "temporary", 29 | "tmp", 30 | "temp", 31 | "tempdir", 32 | "tempfile", 33 | "tmpdir", 34 | "tmpfile" 35 | ], 36 | "files": [ 37 | "lib" 38 | ], 39 | "devDependencies": { 40 | "mocha": "6.2.3" 41 | }, 42 | "repository": { 43 | "type": "git", 44 | "url": "git://github.com/bruce/node-temp.git" 45 | }, 46 | "scripts": { 47 | "test": "mocha test/temp-test.js" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /test/temp-test.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var util = require('util'); 4 | var assert = require('assert'); 5 | 6 | var existsSync = function(path){ 7 | try { 8 | fs.statSync(path); 9 | return true; 10 | } catch (e){ 11 | return false; 12 | } 13 | }; 14 | 15 | // Use path.exists for 0.6 if necessary 16 | var safeExists = fs.exists || path.exists; 17 | 18 | var temp = require('../lib/temp'); 19 | temp.track(); 20 | describe("temp", function() { 21 | it("mkdir", function(done) { 22 | var mkdirPath = null; 23 | temp.mkdir('foo', function(err, tpath) { 24 | assert.ok(!err, "temp.mkdir did not execute without errors"); 25 | assert.ok(path.basename(tpath).slice(0, 3) == 'foo', 'temp.mkdir did not use the prefix'); 26 | assert.ok(existsSync(tpath), 'temp.mkdir did not create the directory'); 27 | 28 | fs.writeFileSync(path.join(tpath, 'a file'), 'a content'); 29 | temp.cleanupSync(); 30 | assert.ok(!existsSync(tpath), 'temp.cleanupSync did not remove the directory'); 31 | 32 | mkdirPath = tpath; 33 | done(); 34 | }); 35 | }); 36 | 37 | it("open", function(done) { 38 | var openPath = null; 39 | temp.open('bar', function(err, info) { 40 | assert.equal('object', typeof(info), "temp.open did not invoke the callback with the err and info object"); 41 | assert.equal('number', typeof(info.fd), 'temp.open did not invoke the callback with an fd'); 42 | fs.writeSync(info.fd, 'foo'); 43 | fs.closeSync(info.fd); 44 | assert.equal('string', typeof(info.path), 'temp.open did not invoke the callback with a path'); 45 | assert.ok(existsSync(info.path), 'temp.open did not create a file'); 46 | 47 | temp.cleanupSync(); 48 | assert.ok(!existsSync(info.path), 'temp.cleanupSync did not remove the file'); 49 | 50 | openPath = info.path; 51 | done(); 52 | }); 53 | }); 54 | 55 | it("stream", function(done) { 56 | var stream = temp.createWriteStream('baz'); 57 | assert.ok(stream instanceof fs.WriteStream, 'temp.createWriteStream did not invoke the callback with the err and stream object'); 58 | stream.write('foo'); 59 | stream.end("More text here\nand more...", function() { 60 | assert.ok(existsSync(stream.path), 'temp.createWriteStream did not create a file'); 61 | 62 | var tempDir = temp.mkdirSync("foobar"); 63 | assert.ok(existsSync(tempDir), 'temp.mkdirTemp did not create a directory'); 64 | 65 | // cleanupSync() 66 | temp.cleanupSync(); 67 | assert.ok(!existsSync(stream.path), 'temp.cleanupSync did not remove the createWriteStream file'); 68 | assert.ok(!existsSync(tempDir), 'temp.cleanupSync did not remove the mkdirSync directory'); 69 | done(); 70 | }); 71 | }); 72 | 73 | it("cleanup", function(done) { 74 | // Make a temp file just to cleanup 75 | var tempFile = temp.openSync(); 76 | fs.writeSync(tempFile.fd, 'foo'); 77 | fs.closeSync(tempFile.fd); 78 | assert.ok(existsSync(tempFile.path), 'temp.openSync did not create a file for cleanup'); 79 | 80 | // run cleanup() 81 | temp.cleanup(function(err, counts) { 82 | assert.ok(!err, 'temp.cleanup did not run without encountering an error'); 83 | assert.ok(!existsSync(tempFile.path), 'temp.cleanup did not remove the openSync file for cleanup'); 84 | assert.equal(1, counts.files, 'temp.cleanup did not report the correct removal statistics'); 85 | done(); 86 | }); 87 | }); 88 | 89 | it("path", function() { 90 | var tempPath = temp.path(); 91 | assert.ok(path.dirname(tempPath) === temp.dir, "temp.path does not work in default os temporary directory"); 92 | 93 | tempPath = temp.path({dir: process.cwd()}); 94 | assert.ok(path.dirname(tempPath) === process.cwd(), "temp.path does not work in user-provided temporary directory"); 95 | }); 96 | 97 | it("singleton", function() { 98 | for (var i=0; i <= 10; i++) { 99 | temp.openSync(); 100 | } 101 | assert.equal(process.listeners('exit').length, 1, 'temp created more than one listener for exit'); 102 | }); 103 | }); 104 | --------------------------------------------------------------------------------