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

path: add Buffer support in path methods #23722

Closed
rossj opened this issue Oct 17, 2018 · 4 comments
Closed

path: add Buffer support in path methods #23722

rossj opened this issue Oct 17, 2018 · 4 comments
Labels
buffer Issues and PRs related to the buffer subsystem. feature request Issues that request new features to be added to Node.js. path Issues and PRs related to the path subsystem. wontfix Issues that will not be fixed.

Comments

@rossj
Copy link

rossj commented Oct 17, 2018

Is your feature request related to a problem? Please describe.
PR #5616 gave us support for Buffer paths in all fs methods, primarily to allow interacting with files of unknown or invalid file encoding. One frustration has been that the path methods, which are often used in conjunction with fs methods, only accept strings. This makes it difficult to perform many higher-level fs operations in a Buffer-based (and therefore encoding agnostic) way, such as recursive move / copy / remove.

Describe the solution you'd like
Ideally, I would think that the path methods could be updated to also accept Buffer inputs, similarly to the fs methods, and to give Buffer output when requested. Looking at the current path.js code, this seems possible but by no means trivial. The current methods primarily iterate through the input strings character-by-character, looking for special values, so I think a similar method could be used for Buffers, or possibly in a string / Buffer agnostic way.

Describe alternatives you've considered
Making these path methods Buffer-based could be well suited for a user-land module, especially since they are primarily utility methods and there's no interaction with the lower-level system.

@ChALkeR ChALkeR added buffer Issues and PRs related to the buffer subsystem. path Issues and PRs related to the path subsystem. feature request Issues that request new features to be added to Node.js. labels Oct 17, 2018
@addaleax
Copy link
Member

Since nobody has weighed in so far…

Making these path methods Buffer-based could be well suited for a user-land module, especially since they are primarily utility methods and there's no interaction with the lower-level system.

I think that might be a good approach, and one that does not necessarily exclude adding core support at a later point.

One difficulty in implementing this would likely be that the path module performs a ton of string concatenations – these are less efficient with Buffers, though…

@ZYSzys
Copy link
Member

ZYSzys commented Oct 26, 2018

IMHO, can we just stringify the path after assertPath if the path passed in is an instance of Buffer ?

@bnoordhuis
Copy link
Member

Closing per Anna's comment.

can we just stringify the path after assertPath if the path passed in is an instance of Buffer ?

No. Binary-to-utf8 conversion isn't lossless.

@bnoordhuis bnoordhuis added the wontfix Issues that will not be fixed. label Nov 19, 2018
@bcoe
Copy link
Contributor

bcoe commented Aug 14, 2021

@rossj take a look at https://github.com/bcoe/path-buffer, I'm starting to dig into this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. feature request Issues that request new features to be added to Node.js. path Issues and PRs related to the path subsystem. wontfix Issues that will not be fixed.
Projects
None yet
Development

No branches or pull requests

6 participants