1 | var temp = require('./temp')
|
2 | var WriteStream = require('fs').WriteStream
|
3 |
|
4 | function TempWriteStream (template, options) {
|
5 | this.template = template
|
6 | WriteStream.call(this, null, options)
|
7 | }
|
8 |
|
9 | TempWriteStream.prototype = Object.create(WriteStream.prototype)
|
10 |
|
11 | TempWriteStream.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 |
|
26 | module.exports = TempWriteStream
|