0

HI I'm new to mac development. I'm using NSTask to unzip files. When unzip encounters image names with special characters ( å, ä, ö ), the files gets skipped. Is there an encoding that I need to specify or if someone can point me to the issue that would be great. Thanks in advance.

NSTask *unzip = [[NSTask alloc] init];
[unzip setLaunchPath:@"/usr/bin/unzip"];
[unzip setArguments:[NSArray arrayWithObjects:@"-u", @"-d", destination, zipFile, nil]];
NSPipe *aPipe = [[NSPipe alloc] init];
[unzip setStandardOutput:aPipe];
[unzip launch];
[unzip waitUntilExit];
[unzip release];

EDIT:

I also found the following from the unzip man page.

https://docs.oracle.com/cd/E88353_01/html/E37839/unzip-1.html

-U
       --unicode
              [UNICODE_SUPPORT]  Control UTF-8 handling.  When UNICODE_SUPPORT
              is available, -U forces UnZip to escape all non-ASCII characters
              from UTF-8 coded filenames as "#Uxxxx' (for UCS-2 characters, or
              "#Lxxxxxx" for  Unicode  codepoints  needing  3  octets).   This
              option  is  provided  mainly  for debugging, when the fairly new
              UTF-8 support is suspected of mangling extracted filenames.

              -UU disables the recognition of UTF-8  encoded  filenames.   The
              handling  of  filename  codings  within  UnZip falls back to the
              behavior of pre-Unicode versions.

              [old, obsolete usage] Leave filenames uppercase  if  created  on
              MS-DOS, VMS, and so on.  See -L.

-U is the aoption to be added how do i add the options in the code?

Lance
  • 19
  • 7
  • Does `unzip` work in Terminal? – Willeke Dec 15 '21 at 20:57
  • how did you create the zip file? could you check if it has unicode names inside, or it has a single byte encoding like cp865? If I compress using macos, I can unzip fine from the terminal with or without -U (it seems that -U has no effect contrary to the docs). If it is not unicode, try to pass the encoding via [environment](https://developer.apple.com/documentation/foundation/nstask/1409412-environment). – battlmonstr Dec 16 '21 at 12:48
  • The `-U` option can be added in the same way as the `-u` and `-d` options. – Willeke Dec 17 '21 at 07:29
  • i would recommend to use tar, "tar -xf archive.zip". Unzip may have problems with encodings – Gintaras Dec 19 '21 at 09:05

0 Answers0