1 var path = require('path')
3 var mkdir = require('../mkdirs')
4 var WriteStream = fs.WriteStream
6 function createOutputStream (file, options) {
8 var dir = path.dirname(file)
9 options = options || {}
11 // if fd is set with an actual number, file is created, hence directory is too
13 return fs.createWriteStream(file, options)
15 // this hacks the WriteStream constructor from calling open()
19 var ws = new WriteStream(file, options)
22 ws.open = function () {
23 ws.fd = null // set actual fd
24 if (dirExists) return oldOpen.call(ws)
26 // this only runs once on first write
27 mkdir.mkdirs(dir, function (err) {
43 module.exports = createOutputStream