On Wed, Aug 20, 2014 at 7:39 AM, Joran Dirk Greef <
jo...@ronomon.com> wrote:
> I am working on file synchronization and would like to know how Node.js
> receives file names from Windows when calling fs.stat or fs.readdir?
Node.js (or rather, libuv) uses the wide character versions of the NT
API for most things. For example, fs.stat() calls CreateFileW() and
fs.readdir() calls FindFirstFileW() and FindNextFileW().
(Note: The NT API uses UTF-16, libuv UTF-8. Libuv internally converts
to and from UTF-16.)
> Does Node.js always return the 8.3 file name equivalent of a long file name
> on Windows? Or does this depend on the version of Windows in use? Will
> Node.js sometimes return the long file name?
>
> For instance, one could use Node.js to write out a file on Windows with a
> long file name. Then trying to check for its existence later by calling
> fs.readdir on the parent directory might perhaps return an 8.3 file name in
> the results without the long file name. Would this be possible?
I don't think libuv ever returns the 8.3 file name. However, I
believe that when (and someone with more Windows experience correct me
if I'm wrong):
1. You create a file or directory with a "long" path (i.e. has a \\?\
prefix and is up to approx. 32,768 characters long), and then
2. Try to reference it through a "short" path (up to MAX_PATH or 260
characters - slightly less for directories), then
3a. You either get a path that's truncated to MAX_PATH characters
(e.g. when scanning a directory), or
3b. You cannot access the file system entity (e.g. when trying to open it.)
3a applies to fs.readdir(). FindFirstFileW() and FindNextFileW()
operate on a WIN32_FIND_DATA structure that's limited to MAX_PATH
characters.
3b is applicable to fs.stat() when you use a "short" path.
> Is there anyway to get both the 8.3 file name and long file name using
> Node.js?
No. You could write a small add-on for GetShortPathName(), however.
Caveat emptor, that article says the path limit is 255 characters but
that's not quite right.