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

BunFile.slice() ignoring end parameter on macOS #8215

Open
tryggvil opened this issue Jan 16, 2024 · 6 comments
Open

BunFile.slice() ignoring end parameter on macOS #8215

tryggvil opened this issue Jan 16, 2024 · 6 comments
Labels
bug Something isn't working web:blob

Comments

@tryggvil
Copy link

tryggvil commented Jan 16, 2024

What version of Bun is running?

1.0.23+83f2432da

What platform is your computer?

macOS

What steps can reproduce the bug?

BunFile.slice does not handle end parameter correctly, on macOS.

const contents = "1234567890abcdefghijklmnokprstuvxyz"
const sliceEndSmallerThanFile = 11

const blb = new Blob([contents]);
const blbSlice = blb.slice(2, sliceEndSmallerThanFile);
const blActualContents = await blbSlice.text();
console.log("blob actualContents:", blActualContents);

await Bun.write("contents.txt", contents);

const fil = Bun.file("contents.txt");
const filSlice = fil.slice(2, sliceEndSmallerThanFile);
const filActualContents = await filSlice.text();
console.log("file actualContents:", filActualContents);

on macOS the output is:

blob actualContents: 34567890a
file actualContents: 34567890abcdefghijklmnokprstuvxyz

returning the whole file contents instead of the slice

What is the expected behavior?

blob actualContents: 34567890a
file actualContents: 34567890a

What do you see instead?

blob actualContents: 34567890a
file actualContents: 34567890abcdefghijklmnokprstuvxyz

Additional information

No response

@tryggvil tryggvil added the bug Something isn't working label Jan 16, 2024
@Electroid Electroid added the web-api Something that relates to a standard Web API label Jan 17, 2024
@truongan07
Copy link

  • Get text of file before slice it ?
const contents = "1234567890abcdefghijklmnokprstuvxyz"
const sliceEndSmallerThanFile = 11

const blb = new Blob([contents]);
const blbSlice = blb.slice(2, sliceEndSmallerThanFile);
const blActualContents = await blbSlice.text();
console.log("blob actualContents:", blActualContents);

await Bun.write("contents.txt", contents);

const fil = Bun.file("contents.txt");
const filActualContents = await fil.text();
const filSlice = filActualContents.slice(2, sliceEndSmallerThanFile);

console.log("file actualContents:", filSlice);

@tryggvil
Copy link
Author

  • Get text of file before slice it ?
const contents = "1234567890abcdefghijklmnokprstuvxyz"
const sliceEndSmallerThanFile = 11

const blb = new Blob([contents]);
const blbSlice = blb.slice(2, sliceEndSmallerThanFile);
const blActualContents = await blbSlice.text();
console.log("blob actualContents:", blActualContents);

await Bun.write("contents.txt", contents);

const fil = Bun.file("contents.txt");
const filActualContents = await fil.text();
const filSlice = filActualContents.slice(2, sliceEndSmallerThanFile);

console.log("file actualContents:", filSlice);

Yes that is a workaround but this is a regression. BunFile.slice() used to work correctly in previous bun versions.

@jdalton
Copy link
Contributor

jdalton commented Jan 22, 2024

Related:
#5980
#6252
#5186

@tryggvil do you know which version of Bun it worked in?
Of interest #6259

@Jakisundays
Copy link

i have the same problem but with audio files.

@tryggvil
Copy link
Author

tryggvil commented Mar 15, 2024

@jdalton Just got around to verify this but this works correctly last in version 1.0.15 , so this broke in version 1.0.16 of Bun. Btw. this is still not working correctly in bun 1.0.31.

@Electroid Electroid added web:blob and removed web-api Something that relates to a standard Web API labels Jun 12, 2024
@gyf304
Copy link

gyf304 commented Jul 10, 2024

still not working correctly in 1.1.17

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

No branches or pull requests

6 participants