{
  "name": "temp",
  "description": "Temporary files and directories",
  "tags": [
    "temporary",
    "temp",
    "tempfile",
    "tempdir",
    "tmpfile",
    "tmpdir",
    "security"
  ],
  "version": "0.6.0",
  "author": {
    "name": "Bruce Williams",
    "email": "bruce@codefluency.com"
  },
  "directories": {
    "lib": "lib"
  },
  "engines": [
    "node >=0.6.0"
  ],
  "main": "./lib/temp",
  "dependencies": {
    "rimraf": "~2.1.4",
    "osenv": "0.0.3"
  },
  "devDependencies": {},
  "repository": {
    "type": "git",
    "url": "git://github.com/bruce/node-temp.git"
  },
  "scripts": {
    "test": "node test/temp-test.js"
  },
  "readme": "node-temp\n=========\n\nTemporary files, directories, and streams for Node.js.\n\nHandles generating a unique file/directory name under the appropriate\nsystem temporary directory, changing the file to an appropriate mode,\nand supports automatic removal (if asked)\n\n`temp` has a similar API to the `fs` module.\n\nNode.js Compatibility\n---------------------\n\nSupports v0.6.0+.\n\n[![Build Status](https://travis-ci.org/bruce/node-temp.png)](https://travis-ci.org/bruce/node-temp)\n\nPlease let me know if you have problems running it on a later version of Node.js or\nhave platform-specific problems.\n\nInstallation\n------------\n\nInstall it using [npm](http://github.com/isaacs/npm):\n\n    $ npm install temp\n\nOr get it directly from:\nhttp://github.com/bruce/node-temp\n\nSynopsis\n--------\n\nYou can create temporary files with `open` and `openSync`, temporary\ndirectories with `mkdir` and `mkdirSync`, or you can get a unique name\nin the system temporary directory with `path`.\n\nWorking copies of the following examples can be found under the\n`examples` directory.\n\n### Temporary Files\n\nTo create a temporary file use `open` or `openSync`, passing\nthem an optional prefix, suffix, or both (see below for details on\naffixes). The object passed to the callback (or returned) has\n`path` and `fd` keys:\n\n```javascript\n{ path: \"/path/to/file\",\n, fd: theFileDescriptor\n}\n```\n\nIn this example we write to a temporary file and call out to `grep` and\n`wc -l` to determine the number of time `foo` occurs in the text.  The\ntemporary file is chmod'd `0600` and cleaned up automatically when the\nprocess at exit (because `temp.track()` is called):\n\n```javascript\nvar temp = require('temp'),\n    fs   = require('fs'),\n    util  = require('util'),\n    exec = require('child_process').exec;\n\n// Automatically track and cleanup files at exit\ntemp.track();\n\n// Fake data\nvar myData = \"foo\\nbar\\nfoo\\nbaz\";\n\n// Process the data (note: error handling omitted)\ntemp.open('myprefix', function(err, info) {\n  fs.write(info.fd, myData);\n  fs.close(info.fd, function(err) {\n    exec(\"grep foo '\" + info.path + \"' | wc -l\", function(err, stdout) {\n      util.puts(stdout.trim());\n    });\n  });\n});\n```\n\n### Want Cleanup? Make sure you ask for it.\n\nAs noted in the example above, if you want temp to track the files and directories\nit creates and handle removing those files and directories on exit, you must call `track()`.\nIt's recommended that you do this immediately after requiring the module.\n\n```javascript\nvar temp = require(\"temp\");\ntemp.track();\n```\n\nWhy is this necessary? In pre-0.6 versions of temp, tracking was automatic. While this works\ngreat for scripts and [Grunt tasks](http://gruntjs.com/), it's not so great for long-running\nserver processes. Since that's arguably what Node.js is _for_, you have to opt-in to tracking.\n\nBut it's easy.\n\n#### Cleanup anytime\n\nWhen tracking, you can `cleanup()` anytime. An object will be returned with cleanup statistics\nand the file/directory lists will be reset.\n\n```javascript\n> temp.cleanup();\n{ files: { removed: 1, missing: 0 },\n  dirs:  { removed: 0, missing: 0 } }\n```\n\nNote: If you're not tracking, `false` will be returned.\n\n### Temporary Directories\n\nTo create a temporary directory, use `mkdir` or `mkdirSync`, passing\nit an optional prefix, suffix, or both (see below for details on affixes).\n\nIn this example we create a temporary directory, write to a file\nwithin it, call out to an external program to create a PDF, and read\nthe result.  While the external process creates a lot of additional\nfiles, the temporary directory is removed automatically at exit (because\n`temp.track()` is called):\n\n```javascript\nvar temp = require('../lib/temp'),\n    fs   = require('fs'),\n    util = require('util'),\n    path = require('path'),\n    exec = require('child_process').exec;\n\n// Automatically track and cleanup files at exit\ntemp.track();\n\n// For use with ConTeXt, http://wiki.contextgarden.net\nvar myData = \"\\\\starttext\\nHello World\\n\\\\stoptext\";\n\ntemp.mkdir('pdfcreator', function(err, dirPath) {\n  var inputPath = path.join(dirPath, 'input.tex')\n  fs.writeFile(inputPath, myData, function(err) {\n    if (err) throw err;\n    process.chdir(dirPath);\n    exec(\"texexec '\" + inputPath + \"'\", function(err) {\n      if (err) throw err;\n      fs.readFile(path.join(dirPath, 'input.pdf'), function(err, data) {\n        if (err) throw err;\n        sys.print(data);\n      });\n    });\n  });\n});\n```\n\n### Temporary Streams\n\nTo create a temporary WriteStream, use 'createWriteStream', which sits\non top of `fs.createWriteStream`. The return value is a\n`fs.WriteStream` whose `path` is registered for removal when\n`temp.cleanup` is called (because `temp.track()` is called).\n\n```javascript\nvar temp = require('temp');\n\n// Automatically track and cleanup files at exit\ntemp.track();\n\nvar stream = temp.createWriteStream();\nstream.write(\"Some data\");\n// Maybe do some other things\nstream.end();\n```\n\n### Affixes\n\nYou can provide custom prefixes and suffixes when creating temporary\nfiles and directories. If you provide a string, it is used as the prefix\nfor the temporary name. If you provide an object with `prefix`,\n`suffix` and `dir` keys, they are used for the temporary name.\n\nHere are some examples:\n\n* `\"aprefix\"`: A simple prefix, prepended to the filename; this is\n  shorthand for:\n* `{prefix: \"aprefix\"}`: A simple prefix, prepended to the filename\n* `{suffix: \".asuffix\"}`: A suffix, appended to the filename\n  (especially useful when the file needs to be named with specific\n  extension for use with an external program).\n* `{prefix: \"myprefix\", suffix: \"mysuffix\"}`: Customize both affixes\n* `{dir: path.join(os.tmpDir()), \"myapp\"}`: default prefix and suffix\n  within a new temporary directory.\n* `null`: Use the defaults for files and directories (prefixes `\"f-\"`\n  and `\"d-\"`, respectively, no suffixes).\n\nIn this simple example we read a `pdf`, write it to a temporary file with\na `.pdf` extension, and close it.\n\n```javascript\nvar fs   = require('fs'),\n    temp = require('temp');\n\nfs.readFile('/path/to/source.pdf', function(err, data) {\n  temp.open({suffix: '.pdf'}, function(err, info) {\n    if (err) throw err;\n    fs.write(info.fd, contents);\n    fs.close(info.fd, function(err) {\n      if (err) throw err;\n      // Do something with the file\n    });\n  });\n});\n```\n\n### Just a path, please\n\nIf you just want a unique name in your temporary directory, use\n`path`:\n\n```javascript\nvar fs = require('fs');\nvar tempName = temp.path({suffix: '.pdf'});\n// Do something with tempName\n```\n\nNote: The file isn't created for you, and the mode is not changed  -- and it\nwill not be removed automatically at exit.  If you use `path`, it's\nall up to you.\n\nUsing it with Grunt\n-------------------\n\nIf you want to use the module with [Grunt](http://gruntjs.com/), make sure you\nuse `async()` in your Gruntfile:\n\n```javascript\nmodule.exports = function (grunt) {\n  var temp = require(\"temp\");\n  temp.track(); // Cleanup files, please\n  grunt.registerTast(\"temptest\", \"Testing temp\", function() {\n\n    var done = this.async(); // Don't forget this!\n\n    grunt.log.writeln(\"About to write a file...\");\n    temp.open('tempfile', function(err, info) {\n      // File writing shenanigans here\n      grunt.log.writeln(\"Wrote a file!\")\n\n      done(); // REALLY don't forget this!\n\n    });\n  });\n};\n```\n\nFor more information, see the [Grunt FAQ](http://gruntjs.com/frequently-asked-questions#why-doesn-t-my-asynchronous-task-complete).\n\nTesting\n-------\n\nFor now, run `test/temp-test.js`:\n\n    $ node test/temp-test.js\n\nContributing\n------------\n\nYou can find the repository at:\nhttp://github.com/bruce/node-temp\n\nIssues/Feature Requests can be submitted at:\nhttp://github.com/bruce/node-temp/issues\n\nI'd really like to hear your feedback, and I'd love to receive your\npull-requests!\n\nCopyright\n---------\n\nCopyright (c) 2010-2012 Bruce Williams. See LICENSE for details.\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/bruce/node-temp/issues"
  },
  "_id": "temp@0.6.0",
  "dist": {
    "shasum": "29d2d63697c79fb5108af11e1cba8edf097877bd"
  },
  "_from": "temp@",
  "_resolved": "https://registry.npmjs.org/temp/-/temp-0.6.0.tgz"
}
