Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

UniZIP - free zipper/unzipper

Discussion in 'Assets and Asset Store' started by tsubaki_t1, Jan 3, 2014.

  1. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    $スクリーンショット 2014-01-03 14.23.24.jpg

    UnityZip



    UnityZip is unzipper/zipper for unity3d.
    It work on iOS/Android/Mac ( probably windows )

    sample.

    Code (csharp):
    1. // unzip
    2. string zipfilePath = Application.temporaryCachePath + "/ZipData.zip"
    3. string exportLocation = Application.temporaryCachePath + "/dir"
    4.  
    5. ZipUtil.Unzip ( zipfilePath, exportLocation);
    6.  
    7. //zip
    8. string exportZipPath = Application.temporaryCachePath + "/dir/args.zip";
    9. string[] fileParths = new string[]{ Application.temporaryCachePath + "/dir/args.txt"}
    10.  
    11. ZipUtil.Zip (exportZipPath, fileParths);
    future
    • support async zip/unzip
    • inform result
    • support password
    • submit assetstore
    • Directry support
     
    Last edited: Feb 16, 2015
  2. GrannySmith

    GrannySmith

    Joined:
    Jul 20, 2012
    Posts:
    8
    Easy to handle. Works like a charm. Also tested on Windows here.

    Thanks for sharing.
     
    tsubaki_t1 likes this.
  3. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    513
    what does this do exactly? is it zipping and exporting or the zipped files are usable inside project/level?
     
  4. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,224
    @tsubaki_t1 Thanks a lot for sharing this. I was wondering if this works also on OSX (I need an unzipper that works from Unity Editor)? Can't test because I'm on Windows.
     
    tsubaki_t1 likes this.
  5. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,337
    Would like to see LZMA instead of ZIP.
     
    tsubaki_t1 likes this.
  6. matrix4x4

    matrix4x4

    Joined:
    Oct 29, 2012
    Posts:
    7
    i meet a error! who can help me ??
    10-09 16:29:31.739: I/Unity(23177): AndroidJavaException: java.lang.ClassNotFoundException: com.tsw.zipper
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJavaObject._CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJavaObject.CallStatic[AndroidJavaObject] (System.String methodName, System.Object[] args) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJavaObject.FindClass (System.String name) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at UnityEngine.AndroidJavaClass..ctor (System.String className) [0x00000] in <filename unknown>:0
    10-09 16:29:31.739: I/Unity(23177): at ZipUtil.Unzip (System.String zipFilePath, System.String location) [0x00000] in <filename unknown>:0
     
  7. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    perhaps, your project no contain zipper class.
    you should add zipper.jar in your project.

    I add sample, you can get it.
    https://github.com/tsubaki/UnityZip/tree/Sample
     
  8. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    It work on OSX. (I'm on OSX. thank you for windows test!)
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,337
    LZMA nudge ;-)

    Actually unity has LZMA in it, they just haven't exposed it. I wish they would. Or is there a way?
     
  10. gacltdev

    gacltdev

    Joined:
    May 31, 2013
    Posts:
    416
    The OpenCTM CSharp project (LGPL licensed) has some LZMA support, since the OpenCTM model format uses it to compress triangle data.
     
    tsubaki_t1 likes this.
  11. FairGamesProductions

    FairGamesProductions

    Joined:
    Mar 8, 2014
    Posts:
    60
    I am very unfamiliar with C#, but I need to use this UnZip tool.
    I can get it to unzip the archive to the specified location, but I need a way to detect the progress of the UnZip.
    Can anyone please help?
     
  12. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    159
    Hi guys,

    I have tested on iOS and it works great!

    Android, however, doesn't seem to work. It doesn't even show an error though.

    • I have the zipper jar file on Plugins > Android folder.
    • I also tried Internal and External (SD Card) Write Access
    • My persistent data path leads to here: /storage/emulated/0/Android/data/com.mydomain.myapp/files/

    ... is there anything else I'm missing here?

    On the sample folder for iOS, PluginsCode > iOS > ZipArchive folder was needed to be added on the XCode project.
    I see there's an Android folder there with zipper.java file, do I need to place this somewhere in my project? If I do, where?

    I'm not really sure if it's just not saving or the plugin isn't working. ¯\_(ツ)_/¯

    Any help would be greatly appreciated. Thanks!
     
    tsubaki_t1 likes this.
  13. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
  14. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    159
    Thanks, it works. I just had to use WWW to pull the file from streaming assets and it worked.
     
  15. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    202
    Hi there!

    Is there a way I can use this to zip up a directory and its contents, rather than pointing to all the files in the directory?

    Thanks in advance!
     
  16. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Hi,

    UniZip does not support the compression of directory.
    perhaps I can support it, but sorry I can't do it right now for work.
     
  17. rickw

    rickw

    Joined:
    Jul 7, 2013
    Posts:
    15
    Hi, total noob question. How do I add this to my project (It will be deployed to Android)?

    There isn't an asset?
    Do I need to create an asset bundle from the source?
    Do I just copy files into my project? If so which ones?

    Cheers.
     
    TomNCatz likes this.
  18. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
  19. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    159
    Does this contain encryption?

    I ask if I would be running into problems when submitting to App Store.

    If yes, is there a way I could disable or take it away?
     
    tsubaki_t1 likes this.
  20. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
  21. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    501
    can we read data from inside without extracting it by code?
     
  22. SAOTA

    SAOTA

    Joined:
    Feb 9, 2015
    Posts:
    220
    I'm not exactly sure what you mean by this

    string[] files = new string[]{ Application.temporaryCachePath + "/dir/args.txt"}

    is this referencing a file called args.txt ? what is in this file.

    I have three files that i generate and would like those files to be zipped.

    I cannot for the life of me get this to work.

    I keep getting this.





    NullReferenceException: Object reference not set to an instance of an object
    ZipUtil.Zip (System.String zipFileName, System.String[] files) (at Assets/plugins/ZipUtil.cs:48)
     
  23. yoieyo

    yoieyo

    Joined:
    Jun 24, 2014
    Posts:
    4
    Is it possible to have a how to video for this? I've done the unzip script, but I've put the file path to .dataPath
    If not, how can I do this?
    My script as of yet is below:

    Code (JavaScript):
    1. using Ionic.Zip;
    2.  
    3. var zipfilePath : String = Application.persistentDataPath + "/Warfare.zip";
    4. var exportLocation : String = Application.persistentDataPath;
    5.  
    6. ZipUtil.Unzip (zipfilePath, exportLocation);
    It is downloading a file and then attempting to unzip the file after, but it wont unzip the actual file, help please
     
    tsubaki_t1 likes this.
  24. yoieyo

    yoieyo

    Joined:
    Jun 24, 2014
    Posts:
    4
    How would I code this in javascript? Is the script I posted above sufficient?
     
  25. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
  26. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    args.txt is a file that was included in the zip of example.

    if you want zip 3 files, you can write it.

    Code (CSharp):
    1. usingUnityEngine;
    2. usingSystem.Collections;
    3. usingSystem.IO;
    4.  
    5. publicclassZipUnzipSample : MonoBehaviour
    6. {
    7.     string[] files =
    8.     {
    9.         "Assets/twitter_icon1.png",
    10.         "Assets/twitter_icon2.png",
    11.         "Assets/twitter_icon3.png",
    12.     };
    13.  
    14.     string zipPath {
    15.         get {
    16.             Directory.CreateDirectory ("ExportPath");
    17.             return Path.Combine ("ExportPath", "file.zip");
    18.         }
    19.     }
    20.  
    21.     public void Zip ()
    22.     {
    23.         ZipUtil.Zip (zipPath, files);
    24.     }
    25. }
    and I add a sample2.
    This sample compresses the multiple files. and unzip it.

    https://github.com/tsubaki/UnityZip/tree/Sample/Assets

     
    SAOTA likes this.
  27. MariuszKowalczyk

    MariuszKowalczyk

    Joined:
    Nov 29, 2011
    Posts:
    237
    If you are looking for a way to have a progress bar, here is the solution, but it works for Windows and Mac only.

    Edit the "Zip.cs" file and make it like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. using System.Runtime.InteropServices;
    5. using Ionic.Zip;
    6. using System.Text;
    7. using System.IO;
    8. using System.ComponentModel;
    9.  
    10. public class ZipUtil
    11. {
    12. #if UNITY_IPHONE
    13.     [DllImport("__Internal")]
    14.     private static extern void unzip (string zipFilePath, string location);
    15.  
    16.     [DllImport("__Internal")]
    17.     private static extern void zip (string zipFilePath);
    18.  
    19.     [DllImport("__Internal")]
    20.     private static extern void addZipFile (string addFile);
    21.  
    22. #endif
    23.  
    24.     public static float progress = 0.0f;
    25.  
    26.     public static void ExtractFile(string zipToUnpack, string unpackDirectory)
    27.     {
    28. #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
    29.         progress = 0.0f;
    30.         Directory.CreateDirectory(unpackDirectory);
    31.  
    32.         BackgroundWorker worker = new BackgroundWorker();
    33.         worker.DoWork += (o, e) =>
    34.         {
    35.             using (ZipFile zip = ZipFile.Read(zipToUnpack))
    36.             {
    37.                 int step = 0;
    38.  
    39.                 foreach (ZipEntry file in zip)
    40.                 {
    41.                     file.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
    42.                     step++;
    43.                     progress = step / (zip.Count * 1.0f);
    44.                 }
    45.             }
    46.         };
    47.      
    48.         worker.RunWorkerAsync();
    49. #endif
    50.     }
    51.  
    52.  
    53.     public static void Unzip (string zipFilePath, string location)
    54.     {
    55. #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
    56.         Directory.CreateDirectory (location);
    57.      
    58.         using (ZipFile zip = ZipFile.Read (zipFilePath)) {
    59.          
    60.             zip.ExtractAll (location, ExtractExistingFileAction.OverwriteSilently);
    61.         }
    62. #elif UNITY_ANDROID
    63.         using (AndroidJavaClass zipper = new AndroidJavaClass ("com.tsw.zipper")) {
    64.             zipper.CallStatic ("unzip", zipFilePath, location);
    65.         }
    66. #elif UNITY_IPHONE
    67.         unzip (zipFilePath, location);
    68. #endif
    69.     }
    70.  
    71.     public static void Zip (string zipFileName, params string[] files)
    72.     {
    73. #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
    74.         string path = Path.GetDirectoryName(zipFileName);
    75.         Directory.CreateDirectory (path);
    76.      
    77.         using (ZipFile zip = new ZipFile()) {
    78.             foreach (string file in files) {
    79.                 zip.AddFile(file, "");
    80.             }
    81.             zip.Save (zipFileName);
    82.         }
    83. #elif UNITY_ANDROID
    84.         using (AndroidJavaClass zipper = new AndroidJavaClass ("com.tsw.zipper")) {
    85.             {
    86.                 zipper.CallStatic ("zip", zipFileName, files);
    87.             }
    88.         }
    89. #elif UNITY_IPHONE
    90.         foreach (string file in files) {
    91.             addZipFile (file);
    92.         }
    93.         zip (zipFileName);
    94. #endif
    95.     }
    96. }
    97.  
    Now you have a new function ExtractFile(), it's working the same as the Unzip() function.

    Use this new function like this:
    Code (CSharp):
    1. ZipUtil.ExtractFile("archive.zip", "unpack_directory");
    2. Debug.Log("progress percent: " + (ZipUtil.progress * 100.0));
     
    SAOTA and tsubaki_t1 like this.
  28. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    14
    Help, I always get this error in XCode when compiling for iOS platform:

    Undefined symbols for architecture armv7:
    "_OBJC_CLASS_$_ZipArchive", referenced from:
    objc-class-ref in UnityZipFile.o
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I have copied the content of "PluginsCode>iOS>ZipArchive" folder into Classes folder of my XCode project.
    I have no idea anymore at this point.

    Please, anybody knows what I do wrong?
     
  29. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Hmm...
    It seem like don’t contain ZipArchive folder in your project.
    Does your project have “ZipArchive.mm” and any files in BuildPhases/Compile sources?
     
  30. Gaus270

    Gaus270

    Joined:
    Jun 19, 2015
    Posts:
    4
    Hi, new to unity and I wish to download this for a project I am currently working on (in Windows 8.1). I simply copy everything in the Assets/Plugins folder into the Plugin folder for my project?
     
  31. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    If you want only Windows 8.1 support only, you can remove plugins/android and plugins/ios.
     
  32. Gaus270

    Gaus270

    Joined:
    Jun 19, 2015
    Posts:
    4
    So that leaves only the Zip c# file and Ionic.Zip.dll in the plugins folder, correct? Thanks again for the timely response!
     
  33. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Correct.
    BTW, I did not check yet in Windows 8.1.
    If it don't work in Windows 8.1, please tell me.
     
  34. Gaus270

    Gaus270

    Joined:
    Jun 19, 2015
    Posts:
    4
    It works perfectly!
     
    tsubaki_t1 likes this.
  35. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,219
    Did anyone test it with OSX/Linux? I need multiplatform solution.
     
  36. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Did not test yet. I will check it.

    perhaps, Unizip work if work Sharpzip work on linux.
     
  37. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Unizip works in Linux.
     
  38. taxfromdk

    taxfromdk

    Joined:
    Oct 30, 2009
    Posts:
    95
    It works for me on Android, but how do I add this to an IOS project?

    I get an error saying

    ZipArchive.mm:270:8: 'release' is unavailable: not available in automatic reference counting mode

    Kind regards

    Jesper
     
  39. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,219
    Great! Just what I needed to implement zip-based solution for my game's levels so they can have comic-style cutscenes.
     
    tsubaki_t1 likes this.
  40. aganley

    aganley

    Joined:
    Oct 20, 2015
    Posts:
    1
    I am using SSIS Script Task. using Ionic.ZIP. Windows Server 2008 R2. I get the following error message. Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. The system cannot find the file specified.
    Code (CSharp):
    1.         public class start
    2.         {
    3.             public void decrypt(string filename)
    4.             {
    5.                 if (string.IsNullOrWhiteSpace(filename))
    6.                     throw new ArgumentNullException("filename");
    7.  
    8.                 string sfilepath = string.Format("\\\\Server\\Data Transfers\\File\\ZipFilePath\\{0}", filename);
    9.                 if (System.IO.File.Exists(sfilepath))
    10.                 {
    11.                     ZipFile fileToExtract = new ZipFile(sfilepath);
    12.                     fileToExtract.Password = "pw";
    13.                     string destination = "\\\\Server\\Data Transfers\\File\\UnZipFilePath";
    14.                     if (System.IO.File.Exists(destination))
    15.                         System.IO.File.Delete(destination);
    16.  
    17.                     fileToExtract.ExtractAll(destination);
    18.                 }
    19.                 else
    20.                     throw new ArgumentException("No file found at location given", paramName: "filename");
    21.             }
    22.         }
     
    tsubaki_t1 likes this.
  41. Dakor

    Dakor

    Joined:
    Sep 2, 2013
    Posts:
    4
    Hey,
    By the way you can use Thread Ninja to do the Unzipping in a background Thread this way it does not block your main Thread :)

    [EDIT] It seems like Thread Ninja and Unizip don't work together on Android, at least not with gearVR.
     
    Last edited: Oct 27, 2015
    tsubaki_t1 likes this.
  42. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    Hi Dakor.
    UniZip use AndroidJavaClass in unzip code for Android.
    UniZip will not work if AndroidJavaClass isn't thread safe.

    I'll try checking it.
     
  43. hacaro76

    hacaro76

    Joined:
    Oct 14, 2015
    Posts:
    20
    Hi All,

    I kindly ask your support for iOS.

    I've built and then I've copied the PluginsCode>iOS> ZipArchive content into my xcode project but i'm unable to build.

    I receive these errors :

    Undefined symbols for architecture arm64:

    "_addZipFile", referenced from:

    _ZipUtil_addZipFile_m674 in Bulk_Assembly-CSharp-firstpass_0.o

    (maybe you meant: _ZipUtil_addZipFile_m674)

    "_zip", referenced from:

    _ZipUtil_zip_m673 in Bulk_Assembly-CSharp-firstpass_0.o

    (maybe you meant: _ZipUtil_zip_m673)

    "_unzip", referenced from:

    _ZipUtil_unzip_m672 in Bulk_Assembly-CSharp-firstpass_0.o

    (maybe you meant: _ZipUtil_unzip_m672)

    ld: symbol(s) not found for architecture arm64

    clang: error: linker command failed with exit code 1 (use -v to see invocation)


    My Configuration is :

    Apple Macbook Pro
    Unity 4.6.9 (Build settings - IL2CPP and NET .2.0)
    Xcode 7.1

    My Target platforms are :

    ipad (older armv7)
    ipad (newer arm64)


    Anyone can help me to solve this ?

    Thanks In advance and
     
  44. soni_619

    soni_619

    Joined:
    Mar 30, 2015
    Posts:
    3
    has anybody tested it on wp8 , for me its not working, is there any workaround or fix .. please let me know
     
  45. shadowfork

    shadowfork

    Joined:
    Jan 8, 2010
    Posts:
    159
    Have any of you guys got this to run on Unity5 | XCode 7.1 / 7.2?

    I drag the ZipArchive folder to Libraries > Plugins > iOS but I always get the 'UnityZipFile.mm > 'ZipArchive.h' file not found error.

    Any help would be greatly appreciated.
    Thanks in advance.
     
    tsubaki_t1 likes this.
  46. vibas-behera095

    vibas-behera095

    Joined:
    Sep 17, 2015
    Posts:
    3
    so, its giving me this error when im trying to unzip. any pointers?:-
    BadReadException: Bad signature (0xE1FFFFB5) at position 0x017A51B0
    Ionic.Zip.ZipEntry.ReadDirEntry (Ionic.Zip.ZipFile zf, System.Collections.Generic.Dictionary`2 previouslySeen)
    Ionic.Zip.ZipFile.ReadCentralDirectory (Ionic.Zip.ZipFile zf)
    Ionic.Zip.ZipFile.ReadIntoInstance (Ionic.Zip.ZipFile zf)
    Rethrow as ZipException: Cannot read that as a ZipFile
    Ionic.Zip.ZipFile.ReadIntoInstance (Ionic.Zip.ZipFile zf)
    Ionic.Zip.ZipFile.Read (System.String fileName, System.IO.TextWriter statusMessageWriter, System.Text.Encoding encoding, System.EventHandler`1 readProgress)
    Ionic.Zip.ZipFile.Read (System.String fileName)


    P.S:- im downloading a zip file from a server, then writing it to disk using www.byte and filestream. The file opens normally in windows, but is not opening when i do zipfile.unzip.
     
  47. tsubaki_t1

    tsubaki_t1

    Joined:
    Jul 2, 2012
    Posts:
    29
    @shadowfork

    I noticed that UniZip does not work if follow manual in xcod7.
    I will change code and manuals soon.

    @vibas.behera095

    How do you compress it?
     
  48. vibas-behera095

    vibas-behera095

    Joined:
    Sep 17, 2015
    Posts:
    3
    well, that error was occurring due to some extra bytes being written, successfully corrected that. It works perfectly in android as well.. but when building the program for IOS, it gives an error
    " Fatal error in Mono CIL Linker System.Exception: Error processing method: 'System.Void Ionic.Zip.WinZipAesCipherStream::TraceOutput(System.String,System.Object[])' in assembly: 'Ionic.Zip.dll' --->"
     
  49. Delaley

    Delaley

    Joined:
    Jan 19, 2016
    Posts:
    6
    #Thanks, it works. I just had to use WWW to pull the file from
    streaming assets and it worked.

    Please can you help me here.
    How did you it.
    Maybe a code would do.
    Please I desperately need your help.
     
  50. toannguyen.mm

    toannguyen.mm

    Joined:
    Dec 3, 2015
    Posts:
    1
    @tsubaki_t1
    Can it work on Unity 5.3 and Xcode 7.2?