execa icon indicating copy to clipboard operation
execa copied to clipboard

Automatically wait for file streams to open

Open jamestalmage opened this issue 8 years ago • 9 comments

It might be possible to wait for the open event on file streams (if we can find a way to detect that a stream is in fact a file stream, and that it will indeed eventually open).

See the discussion here

jamestalmage avatar Mar 29 '17 17:03 jamestalmage

We could detect the follow custom properties attached to it:

  path: 'ad',
  fd: null,
  flags: 'w',
  mode: 438,

Maybe we should add isStream.fsWritable() and isStream.fsReadable() methods to is-stream?

sindresorhus avatar Mar 29 '17 17:03 sindresorhus

I just made is-file-stream. https://github.com/jamestalmage/is-file-stream

jamestalmage avatar Mar 29 '17 18:03 jamestalmage

Even better. Less bloat for is-stream. The module looks good.

sindresorhus avatar Mar 29 '17 19:03 sindresorhus

This is a great idea. Makes working with file streams much easier. I will have a look at implementing this.

SamVerschueren avatar Mar 30 '17 05:03 SamVerschueren

I think we should also at least try to get this into Node.js core by opening an issue argumenting it's the expected behavior.

sindresorhus avatar Mar 30 '17 05:03 sindresorhus

Good point. We probably all know how this will end but at least we can try.

SamVerschueren avatar Mar 30 '17 06:03 SamVerschueren

At least we can then reference Node.js' unwillingness to good UX. It's always worth trying to improve core Node.js if possible, as it benefits of lot more users, and of course less code for us to maintain.

sindresorhus avatar Mar 30 '17 06:03 sindresorhus

Totally agree with that.

SamVerschueren avatar Mar 30 '17 06:03 SamVerschueren

Basically, they only allow streams that have file descriptors, and under the hood, they convert streams to those file descriptors.

It would have been way less confusing for them not to allow streams, and just provide a findUnderlyingFileDescriptor(stream).

Streams passed to child_process.spawn are handled completely differently than anywhere else in Node-land. Not having the magical "convenience" of this automatic unwrapping would have ultimately been so much less confusing.

jamestalmage avatar Mar 30 '17 06:03 jamestalmage

Should this be closed in favor for https://github.com/sindresorhus/execa/issues/617?

(Also relevant: https://github.com/sindresorhus/execa/issues/616)

ehmicky avatar Dec 18 '23 04:12 ehmicky

Yup

sindresorhus avatar Dec 18 '23 22:12 sindresorhus