UNPKG

632 BJavaScriptView Raw
1var temp = require('./temp')
2var WriteStream = require('fs').WriteStream
3
4function TempWriteStream (template, options) {
5 this.template = template
6 WriteStream.call(this, null, options)
7}
8
9TempWriteStream.prototype = Object.create(WriteStream.prototype)
10
11TempWriteStream.prototype.open = function open () {
12 temp.open(this.template, this.flags, this.mode, function (err, info) {
13 if (err) {
14 this.destroy()
15 this.emit('error', err)
16 return
17 }
18
19 this.fd = info.fd
20 this.path = info.path
21 this.emit('path', info.path)
22 this.emit('open', info.fd)
23 }.bind(this))
24}
25
26module.exports = TempWriteStream