Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to write out a NodeJS stream to disk #11633

Closed
l1mey112 opened this issue Jun 6, 2024 · 1 comment · Fixed by #13044
Closed

Failure to write out a NodeJS stream to disk #11633

l1mey112 opened this issue Jun 6, 2024 · 1 comment · Fixed by #13044
Labels
bug Something isn't working needs triage

Comments

@l1mey112
Copy link

l1mey112 commented Jun 6, 2024

What version of Bun is running?

1.1.10+5102a9443

What platform is your computer?

Linux 6.1.0-13-amd64 x86_64 unknown

What steps can reproduce the bug?

bun i librespot

Inside bun when running the below program the file contents being written are just the string [object EventEmitter] and not the actual OGG data. Im sure bun has a deficiency here with NodeJS streams.

import Librespot from 'librespot'
import fs from 'fs/promises'

const spotify = new Librespot({})

await spotify.login('username', 'pasword')

const track = await spotify.get.track('7suTW2CMSgQdioqvEvaALy')

await fs.writeFile('example.ogg', track.stream)
await spotify.disconnect()

What is the expected behavior?

To properly write the data into the file, not just that string.

What do you see instead?

[object EventEmitter]

Additional information

It works perfectly in NodeJS.

@maximehuylebroeck
Copy link

maximehuylebroeck commented Aug 2, 2024

Same for things like readable streams you'll see [object object]

easy to reproduce with this:

import * as fs from 'fs/promises';
import { Readable } from 'stream';

// Create a readable stream (for demonstration purposes)
const exampleStream = Readable.from(['Hello, ', 'world!']);

// Specify the file path
const filePath = 'output.txt';

async function writeStreamToFile(readableStream, filePath) {
    try {
        // Write the stream directly to the file
        await fs.writeFile(filePath, readableStream);

        console.log('File written successfully');
    } catch (error) {
        console.error('Error writing file:', error);
    }
}

// Write the stream to the file
writeStreamToFile(exampleStream, filePath);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants