-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
fs.watch doesn't support Chinese characters #2088
Comments
I just tried this on Linux 3.19 x64 and it ran fine. This may be a windows specific issue. Can you please post the test script to make sure we're attempting the same thing? |
var root = path.join(__dirname,'./doc');
fs.watch(root,function(event,filename){
console.log(event,filename);
}); Create a new folder and try to rename it to 新建文夹件 |
Can you output |
I can't output them. @trevnorris |
The command |
sorry.It works and I got them. |
Can you post the output? |
length: 15 |
Thanks. And yeah. It's borked on Linux too. Didn't test the right thing. |
That's because for better or worse, On Windows, UTF-8 is the right encoding because libuv decodes the filename to UTF-8 before passing it on to io.js. On Unices, it's complicated; filenames don't have an encoding, they're just byte strings, except on OS X, where they are stored as NFD-normalized UTF-8. |
@daysv Have a work around for you. Try the following: fs.watch(PATH, function(event, filename) {
console.log(Buffer(filename, 'binary').toString());
}); That will reinterpret the one-byte encoded string as UTF8. |
@trevnorris Thanks! ^_^ |
@bnoordhuis Thanks for the commit reference and reasoning. Think this, along with the work around, should be documented? EDIT: Or possibly this work around could be implemented internally to make the difference transparent. |
I think we should fix it but it's part of a broader theme where file path handling is sub-optimal. We probably need some platform-specific code for encoding them to JS strings. |
I reported same issue at nodejs/node-v0.x-archive#25504. |
I don't get it. Doesn't Node.js assume UTF-8 encoding everywhere else? |
Hi, @seishun , is your patch included in the last release(v5.1.1)? This issue hasn't solved yet.(Tested on windows 10 64 bit) |
@UncleBill the fix was postponed to v6.0.0. |
@seishun Oh, got it. Thanks! |
@trevnorris @bnoordhuis ... thinking about this one further... one possible solution would be to add an |
This makes several changes: 1. Allow path/filename to be passed in as a Buffer on fs methods 2. Add `options.encoding` to fs.readdir, fs.readdirSync, fs.readlink, fs.readlinkSync and fs.watch. 3. Documentation updates For 1... it's now possible to do: ```js fs.open(Buffer('/fs/foo/bar'), 'w+', (err, fd) => { }); ``` For 2... ```js 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 ```js 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: nodejs#2088 Refs: nodejs#3519 Alternate: nodejs#3401
Thanks @jasnell! |
info
io.js, v2.3.1
Windows 7, 64bit
The text was updated successfully, but these errors were encountered: