Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fails with non-existing file #8

naholyr opened this Issue · 2 comments

1 participant


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

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


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

but also throws

        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:


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


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 referenced this issue from a commit
@naholyr naholyr Create a WriteStream instead of emitting an error when calling `filed…
…("non-existing-file")`. Beware this will stick to documentation, but it will create a file (as `fs.createWriteStream` does).


Closed by PR

@naholyr naholyr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.