oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.71k stars 2.72k forks source link

A minor internal bug in the node:fs ReadStream#constructor #8102

Closed Edgar-P-yan closed 9 months ago

Edgar-P-yan commented 9 months ago

What version of Bun is running?

main branch

What platform is your computer?

all

What steps can reproduce the bug?

Found this when was reading through the sources, looks like a bug. Pass an encoding like 'utf-8' instead of a parameters object as the second argument to fs.createReadStream('file/path', 'utf-8'), by design it is allowed. This will get passed down to the ReadStream class. At this line: https://github.com/oven-sh/bun/blob/0bfe3760f6dd542603aab239bb31034171bb7191/src/js/node/fs.js#L600 the options gets deconstructed into an object when calling super:

super(ptr, {
  ...options,
  encoding,
  autoDestroy,
  autoClose,
  emitClose,
  highWaterMark,
});

In case if options is a string representing the encoding (which is by the protocol) the resulting object will look something like this:

{
  0: 'u',
  1: 't',
  2: 'f',
  3: '-',
  4: '8',
  encoding: 'utf-8',
  autoDestroy: ...
  ...
}

I thing this does not break anything, but still clutters internal object shapes.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Jarred-Sumner commented 9 months ago

Fixed by @keepdying in #8212