Fails with non-existing file #8

Closed
naholyr opened this Issue Oct 30, 2011 · 2 comments

Projects

None yet

1 participant

@naholyr
naholyr commented Oct 30, 2011

In a unpiped context, creating an instance with a non-existing path fails:

var filed = require("filed")
f = filed("./unexisting-file")

returns

{ writable: true,
  readable: true,
  buffers: [],
  path: './toto.txt',
  index: 'index.html',
  _events: { pipe: [Function] },
  buffering: true,
  mimetype: 'application/octet-stream' }

but also throws

events.js:48
        throw arguments[1]; // Unhandled 'error' event
        ^
Error: ENOENT, No such file or directory './toto.txt'

no time to call write() or end(), it has already failed

I suppose it's linked to the fact that there is no pipe around, because this works:

filed("existing-file").pipe(filed("unexisting-file"))

Anyway, the very first example of the README fails because of this issue :x

@naholyr
naholyr commented Oct 30, 2011

I found a way to fix it, at line 46:

if (err && !self.dest && !self.src) return self.emit('error', err)

we should add before this line:

if (err && err.code === 'ENOENT' && !self.dest && !self.src) self.src = self.path

This way the call to finish() would go until line 141 and create a WriteStream.

@naholyr
naholyr commented Oct 30, 2011

Closed by PR

@naholyr naholyr closed this Oct 30, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment