Skip to content

Incorrect slice() from fs.openAsBlob() #53908

Description

@jleedev

Version

v22.5.0

Platform

Linux penguin 6.6.32-02873-ge0e03a627715 #1 SMP PREEMPT Mon, 1 Jul 2024 20:29:42 +0000 aarch64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

> await fs.promises.writeFile('a.txt', 'abcdefghij')
> blob = await fs.openAsBlob('a.txt')
Blob { size: 10, type: '' }
> await _.text()
'abcdefghij'
> blob.slice(3)
Blob { size: 7, type: '' }
> await _.text()
'defghij'
> blob.slice(3).slice()
Blob { size: 7, type: '' }
> await _.text()
'defg'

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

slice() with no arguments should be equivalent to slice(0, length) and return the entire blob; both of those are incorrectly returning something else.

What do you see instead?

The returned Blob object purports to have the expected size, but when it is read it has the wrong length.

Additional information

No response

Activity

  1. avivkeller commented on Jul 17, 2024

    @avivkeller
    Member

    Reproducible:

    import fs from 'node:fs';
    
    // await fs.writeFile('file.txt', '123456789')
    
    const blob = await fs.openAsBlob('file.txt');
    console.log(await blob.text());
    
    console.log(await blob.slice(3).text());
    
    console.log(await blob.slice(3).slice().text());
    └─$ node index.mjs
    123456789
    456789
    456
    
  2. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Jul 17, 2024
  3. avivkeller commented on Jul 17, 2024

    @avivkeller
    Member

    It however does not occur with non-fs blobs:

    import { Blob } from 'node:buffer';
    
    const blob = new Blob(['123456789']);
    
    console.log(await blob.text());
    console.log(await blob.slice(3).text());
    console.log(await blob.slice(3).slice().text());
    └─$ node index.mjs
    123456789
    456789
    456789
    
  4. HardikGoyal2003 commented on Jul 17, 2024

    @HardikGoyal2003

    Hey @redyetidev, could you assign me this issue? I'd like to work on it, if that's alright.

  5. avivkeller commented on Jul 17, 2024

    @avivkeller
    Member

    Feel free to work on it, but issues aren't typically assigned (except when they are self assigned).

    If you have an improvement, feel free to submit a PR.

  6. jleedev commented on Jul 20, 2024

    @jleedev
    ContributorAuthor

    new_end = std::min(end.value(), end_);

    Should be:

     new_end = std::min(end.value() + start_, end_); 
  7. avivkeller commented on Jul 20, 2024

    @avivkeller
    Member

    Feel free to submit a PR with suggestions to the Conway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions