Created
January 12, 2014 20:33
-
-
Save jwilm/8390194 to your computer and use it in GitHub Desktop.
CoffeeScript make temporary dir function for node - uses Bluebird promises and child_process.spawn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spawn = require('child_process').spawn | |
Bluebird = require 'bluebird' | |
mktemp = (pattern) -> | |
deferred = Bluebird.defer() | |
out = [] | |
s = spawn('mktemp', ['-t', pattern, '-d']) | |
s.stderr.setEncoding 'utf8' | |
s.stdout.setEncoding 'utf8' | |
s.stdout.on 'data', (data) -> | |
out.push data | |
s.stderr.on 'data', (err) -> | |
out.push err | |
s.on 'close', (code) -> | |
return deferred.reject { code: code, err: out.join('\n') } unless code is 0 | |
deferred.resolve out[0] | |
return deferred.promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment