Blame view

node_modules/mktmpdir/README.md 1.63 KB
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  mktmpdir
  ==================
  [![Build Status](https://travis-ci.org/nkzawa/mktmpdir.png?branch=master)](https://travis-ci.org/nkzawa/mktmpdir)
  
  mktmpdir creates a temporary directory, ported from Ruby's [Dir.mktmpdir](http://www.ruby-doc.org/stdlib-2.0/libdoc/tmpdir/rdoc/Dir.html#method-c-mktmpdir).
  
  ```js
  var mktmpdir = require('mktmpdir');
  
  mktmpdir(function(err, dir, done) {
    if (err) throw err;
    // use the directory...
    fs.writeFile(dir + '/foo', 'hello, World', done);
  }, function(err, dir) {
    // after the directory is removed.
  });
  ```
  
  ## Installation
      $ npm install mktmpdir
  
  ## Usage
  
  ### mktmpdir([prefixSuffix], [tmpdir], callback, [onend])
  The prefix and suffix of the name of the directory is specified by `prefixSuffix`.
  The directory is created under `tmpdir` or `os.tmpdir()` with 0700 permission.
  
  ## Examples
  
  ```js
  mktmpdir(function(err, dir) {
    // dir is ".../d..."
  });
  
  mktmpdir('foo', function(err, dir) {
    // dir is ".../foo..."
  });
  
  mktmpdir(['foo', 'bar'], function(err, dir) {
    // dir is ".../foo...bar"
  });
  
  mktmpdir(null, '/var/tmp', function(err, dir) {
    // dir is "/var/tmp/d..."
  });
  
  // If a callback is invoked, the path of the directory and its contents are removed.
  mktmpdir(function(err, dir, done) {
    if (err) throw err;
    fs.open(dir + '/foo', 'w', function(err, fd) {
      done(err);
    });
  }, function(err) {
    // the directory has been removed.
  });
  
  // If a callback is not invoked, `mktmpdir` doesn't remove the directory.
  mktmpdir(function(err, dir) {
    if (err) throw err;
    fs.open(dir + '/foo', 'w', function(err, fd) {
      // remove the directory.
      exec('rm -rf ' + dir);
    });
  });
  ```
  
  ## License
  MIT