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

fs.promises FileHandle.read() not working with object argument as stated in docs. #34176

Closed
branisha opened this issue Jul 2, 2020 · 1 comment

Comments

@branisha
Copy link
Contributor

branisha commented Jul 2, 2020

  • Version: v14.4.0
  • Platform: Linux arch 5.7.2-arch1-1
  • Subsystem: fs.promises FileHandle

What steps will reproduce the bug?

Using FileHandle.read() with object argument.
This example throws TypeError:

const fs_p = require('fs').promises;
fs_p.open('exampleFile.txt', 'r')
    .then((fileHandler) => {
        const header_buffer = Buffer.alloc(10);
        fileHandler.read({ buffer: header_buffer, offset: 12 })
            .then(({ bytesRead, buffer }) => {
                console.log("Reading")
            }).catch((err) => {
                throw err;
            });
    }).catch((err) => {
        throw err;
    });

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

Everytime you use object as argument.

What is the expected behavior?

Method should accept object as parameter, as stated in docs here.

What do you see instead?

TypeError [ERR_INVALID_ARG_TYPE]: The "buffer" argument must be an instance of Buffer, TypedArray, or DataView. Received an instance of Object

Additional information

This bug dosen't seem too complicated, maybe I could fix it.

@jfriend00
Copy link

jfriend00 commented Jul 2, 2020

Problem confirmed on Windows 10. You can see diagnosis of the problem here: https://stackoverflow.com/questions/62704475/node-js-filehandle-read-method-throws-invalid-argument-error/62704825. The implementation of handle.read() does not appear to contain any code that supports the handle.read(optionsObject) form of the .read() because a quick call to validateBuffer() fails immediately and never detects that an object was passed and that object needs to be unpacked into the individual arguments. I would guess that there must also be a missing test case for the handle.read(optionsObject) use case too.

@aduh95 aduh95 closed this as completed in d05c271 Nov 18, 2020
codebytere pushed a commit that referenced this issue Nov 22, 2020
PR-URL: #34180
Fixes: #34176
Refs: https://nodejs.org/api/fs.html#fs_filehandle_read_options
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Dec 10, 2020
PR-URL: #34180
Fixes: #34176
Refs: https://nodejs.org/api/fs.html#fs_filehandle_read_options
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Dec 10, 2020
PR-URL: #34180
Fixes: #34176
Refs: https://nodejs.org/api/fs.html#fs_filehandle_read_options
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
BethGriggs pushed a commit that referenced this issue Dec 15, 2020
PR-URL: #34180
Fixes: #34176
Refs: https://nodejs.org/api/fs.html#fs_filehandle_read_options
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants