zstd icon indicating copy to clipboard operation
zstd copied to clipboard

zstd fails to process some filenames on Windows [we need a hero]

Open sergeevabc opened this issue 1 year ago • 3 comments

Windows 7 x64, zstd 1.5.5

$ dir /b
birds.txt
pájaros.txt
vögel.txt
птицы.txt

$ zstd *.*
zstd: can't stat pajaros.txt : No such file or directory -- ignored
zstd: can't stat vogel.txt : No such file or directory -- ignored
  2 files compressed : 85.71% (  3.00 KiB =>   2.57 KiB)
 
$ dir /b *.zst
birds.txt.zst
птицы.txt.zst

@Cyan4973 said zstd doesn't do anything special, it uses the C standard fopen() function. This should be naturally compatible with any utf-8 character set. But I suspect Windows does something different with the character set, so there might be a need to employ other non-portable Windows variants of > fopen for these scenarios.

sergeevabc avatar Jan 24 '24 18:01 sergeevabc

This is what I get with v1.5.5 64-bit under Windows 10:

c:\xxx\zzz>dir /b
vögel.txt

c:\xxx\zzz>zstd *.*
v÷gel.txt            :262.50%   (     8 B =>     21 B, v÷gel.txt.zst)

c:\xxx\zzz>dir /b
vögel.txt
vögel.txt.zst

a1880 avatar Jan 30 '24 23:01 a1880

It seems Windows doesn't deal with UTF-8 by default https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170. Seems the safest solution is to use _wfopen and convert narrow string to wide with MultiByteToWideChar function.

flagarde avatar Jan 31 '24 17:01 flagarde

In my example, the file vögel.txt.zst was created correctly. But the text output to show the progress is not correct. Therefore, I figure that the fopen() call is ok.

a1880 avatar Jan 31 '24 17:01 a1880