fs: add Buffer support in fs methods by jasnell · Pull Request #5616 · nodejs/node (original) (raw)
This makes several changes:
- Allow path/filename to be passed in as a Buffer on fs methods
- Add
options.encoding
to fs.readdir, fs.readdirSync, fs.readlink, fs.readlinkSync and fs.watch. - Documentation updates
For 1... it's now possible to do:
fs.open(Buffer('/fs/foo/bar'), 'w+', (err, fd) => { });
For 2...
fs.readdir('/fs/foo/bar', {encoding:'hex'}, (err,list) => { });
fs.readdir('/fs/foo/bar', {encoding:'buffer'}, (err, list) => { });
encoding can also be passed as a string
fs.readdir('/fs/foo/bar', 'hex', (err,list) => { });
The default encoding is set to UTF8 so this addresses the discrepency that existed previously between fs.readdir and fs.watch handling filenames differently.
Fixes: #2088 Refs: #3519 PR-URL: #5616 Reviewed-By: Ben Noordhuis info@bnoordhuis.nl Reviewed-By: Trevor Norris trev.norris@gmail.com