oven-sh / bun

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

readLine.createInterface closes early #12125

Open dtorres opened 3 months ago

dtorres commented 3 months ago

What version of Bun is running?

1.1.15+b23ba1fe1

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

Create a test file at /tmp/testfile.txt with the following content:

1
2
3
4

Run this script:

import { createReadStream, existsSync } from 'fs';
import { createInterface } from 'readline';

const fileStream = createReadStream("/tmp/testfile.txt", {encoding: "latin1"});

  const rl = createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });

  for await (const line of rl) {
    console.log(`Line 1: ${line}`)
    break;
  }

  for await (const line of rl) {
    console.log(`Line 2: ${line}`)
    break;
  }

  for await (const line of rl) {
    console.log(`Line 3: ${line}`)
    break;
  }

  for await (const line of rl) {
    console.log(`Line 4: ${line}`)
    break;
  }

What is the expected behavior?

Line 1: 1
Line 2: 2
Line 3: 3
Line 4: 4

What do you see instead?

Line 1: 1

Additional information

This was tested agains Node v22.3.0 which works as expected

dtorres commented 3 months ago

This might be a bug (or change in behaviour) on Node actually as their own documentation claims that Bun's behaviour is what's expected.

Perhaps the documentation hasn't been updated(?). Because the undocumented behaviour makes more sense tbh