fs: honor encoding option in glob APIs#62068
Conversation
|
Compact update: this addresses the #59202 review blockers (no cached-dirent mutation, YAML metadata added, invalid-encoding + absolute-pattern tests). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62068 +/- ##
==========================================
- Coverage 91.63% 89.66% -1.97%
==========================================
Files 337 676 +339
Lines 140376 206327 +65951
Branches 21768 39541 +17773
==========================================
+ Hits 128627 184994 +56367
- Misses 11527 13464 +1937
- Partials 222 7869 +7647
🚀 New features to boost your workflow:
|
Align glob, globSync, and fsPromises.glob with encoding semantics. When encoding is 'buffer', return Buffer paths and Buffer dirent names. Add regression tests and documentation updates to lock behavior.
8aaa9f4 to
2622646
Compare
| If a string array is provided, each string should be a glob pattern that | ||
| specifies paths to exclude. Note: Negation patterns (e.g., '!foo.js') are | ||
| not supported. | ||
| * `encoding` {string} The path encoding. If set to `'buffer'`, the iterator |
There was a problem hiding this comment.
It cloud be better if the user only can pass an encoding option of Buffer.from . Is the encoding option value buffer not necessary?
There was a problem hiding this comment.
Thanks, good question. I kept encoding: 'buffer' intentionally because the original issue is about preserving raw filename bytes for names that are not valid UTF-8. Restricting this to string encodings would still force decoding and would not solve that case. This follows the existing fs pattern where buffer is the opt-in for returning raw bytes, and I kept withFileTypes consistent so dirent.name follows the same behavior.
Summary
encodingforfs.globSync(),fs.glob(), andfsPromises.glob()soencoding: 'buffer'returnsBufferpaths andBufferdirent names withwithFileTypesTesting
python3 tools/test.py test/parallel/test-fs-glob.mjs test/parallel/test-fs-glob-throw.mjs test/parallel/test-fs-readdir-buffer.js test/parallel/test-fs-readdir-types.js#59202.