You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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…
Activity
addaleax commentedon Oct 20, 2018
Since nobody has weighed in so far…
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
pathmodule performs a ton of string concatenations – these are less efficient withBuffers, though…ZYSzys commentedon Oct 26, 2018
IMHO, can we just stringify the
pathafterassertPathif thepathpassed in is an instance ofBuffer?bnoordhuis commentedon Nov 19, 2018
Closing per Anna's comment.
No. Binary-to-utf8 conversion isn't lossless.
bcoe commentedon Aug 14, 2021
@rossj take a look at https://github.com/bcoe/path-buffer, I'm starting to dig into this problem.