Skip to content

fs readdir with buffer and file types problem #33348

@vasyanewlifehere

Description

@vasyanewlifehere
  • Version: 12.16.3
  • Platform: linux64
  • Subsystem: gentoo

What steps will reproduce the bug?

reading directory with files names using buffer as path does not work.

const fs = require('fs');
fs.readdir( Buffer.from( "."),{withFileTypes:true,encoding:"buffer"},(e,d)=>console.log("dir",d));

It works correct in version 12.14.0 but after upgrade it stopped to work.
using it without files types works:
// fs.readdir( Buffer.from( "."),{withFileTypes:false,encoding:"buffer"},(e,d)=>console.log("dir",d));

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

every time

What is the expected behavior?

get directory entries with file types i.e. array of Dirent objects

What do you see instead?

error message:

Uncaught:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Buffer
    at validateString (internal/validators.js:117:11)
    at Object.join (path.js:1039:7)
    at getDirents (internal/fs/utils.js:159:39)
    at FSReqCallback.req.oncomplete (fs.js:858:7) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Additional information

This bug is degradation because it doesn't exists in version 12.14.0 and present in versions 12.16.1 and 12.16.3 at least.
I use buffer instead of string because working with my old archives with non utf-8 names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.fsIssues and PRs related to the fs subsystem / file system.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions