How I can readdir that contains filename with non utf-8 characters(e.g. cp1251)?
fs.readdir("./dir1", function(err, files){
console.log(files[0], new Buffer(files[0]));
});
response: 'Forget (������).mp3', Buffer <46 6f 72 67 65 74 20 28 ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd ef bf bd 29 2e 6d 70 33>
upd: files was uploaded from proftpd in cp1251 encoding name
# ls dir1
Forget (������).mp3
upd2:
ls dir1 | iconv -f cp1251 -t utf8
Forget (гитара).mp3
Obviously, the upload via FTP already got the characters wrong ... try renaming the file manually, and re-run your Node.js app again. This time, it should work :-)
You can see that the file name is broken already in the buffer:
46 6f 72 67 65 74 20 28 ef bf bd ef bf bd ef bf bd
ef bf bd ef bf bd ef bf bd 29 2e 6d 70 33
The term ef bf bd is repeated six times, which perfectly matches the six-times occurence of the invalid character, and very obviously it's not the original string гитара.