Search Unity

[RELEASED] zip / gzip native multiplatfrom plugin

Discussion in 'Assets and Asset Store' started by elias_t, Jul 8, 2015.

  1. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Zip / gzip multiplatform native plugin.

    https://assetstore.unity.com/packag...nt/zip-gzip-multiplatform-native-plugin-39411


    This is a shared library for Android, iOS*, OSX, Windows, Linux and webGL** to compress/decompress zip/gzip/tar/bz2 files and buffers.


    **WebGL supports all functions except the ones that require file system access.


    If you are publishing for MacOS on the AppStore please do the following to codesign the bundle:

    1. Remove all the meta files from inside the .bundle.
    2. Remove (if any) folder named CodeSignature.
    3. Find the Info.plist file and change the bundleID to one of your own.


    It is also part of the 7z/lzma/zip package in the asset store here:7zip/lzma/zip plugins

    Fast zip/gzip compression and decompression with a clean and simple interface. Very easy to use. Well commented example and documentation.

    The plugin is about 7x times faster in compression speed and 3x times faster in decompression speed compared to SharpZipLib.


    - compress/decompress buffers to/from zlib/gzip streams.
    - recursive directory compression/decompression.
    - compress/decompress single files.
    - encryption / decryption.
    - append files to existing zip archives.
    - compress a buffer and write it or append it to a zip archive.
    - get file and size info of all the files or a specific file from a zip archive.
    - extract a single file out of a zip archive.
    - extract multiple entries out of a zip archive.
    - extract a list of entries to the file system or in multiple buffers.
    - decompress a file of a zip archive to a byte buffer.
    - delete an entry in a zip archive.
    - replace an entry in a zip archive.
    - get progress of extraction when the zip archive has multiple files.
    - get byte level progress of compression/decompression (single or multiple files).
    - create in Memory zip files and manipulate them from there.
    - Support of split zip files compress/decompress (1.zip. 1.z01, 1.z02, ...)
    - decompression of split zip archives (in the form of 1.zip, 1.z01, 1.z02, ...)
    - ability to discover merged/hidden zip/gzip archives in files or buffers and extract from there.
    - bz2/zlib compression-decompression methods. (bz2 method not available for MacOS/iOS/tvOS & webGL)
    - buffers can be treated as files. That means if you have a file in www.bytes you can perform operations directly on the buffer.
    - support for native file buffers to avoid memory spikes when decompressing from managed buffers.
    - support for STORE method when setting level of compression to zero.
    - create/decompress gzip files and buffers.
    - decompress gzip from buffer to the file system.
    - ability to cancel most zip/unzip/gzip/tar operations when they are called from a Thread.
    - ability to create tar archives from directories or list of files with byte level progress.
    - untar and untar entry support with byte level progress.
    - compress/decompress of tar.gz, tar.bz2 with progress.
    - create and decompress bz2 archives with progress.
    - thread safe
    - utf-8 support


    The ios and OSX libraries are compiled as universal. That means that they will support 32 and 64 bit builds.
    The Windows and Linux libraries are compiled for x86 and x86_64 build modes.
    The Android lib is compiled for armeabi-v7a, x86, x86_64 and arm64-v8a.
    (Armv7 and x86 include also plugins with minimum api=24 (7.0 Nougat) to support files larger than 2GB.)
     

    Attached Files:

    Last edited: Nov 21, 2022
  2. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi.

    There was a bug in the compressDir function.

    edit: the 1.02 update is up now correcting the above bug.
     
    Last edited: Jul 20, 2015
  3. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
  4. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Pretty cool. Bought!
     
  5. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Thanks.

    Some people are getting an error when running the plugin in the windows editor.

    It is because the are missing the vc++2013 redistributable.

    Download the vc++2013 redist from here: https://www.microsoft.com/en-us/download/details.aspx?id=40784

    edit:
    I have uploaded an update with the vc++2013 dependency removed.

    edit2: update 1.03 is up.
     
    Last edited: Aug 15, 2015
  6. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I can confirm that the Linux plugin works also in the new unity Linux editor.
     
  7. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    The compressDir function works a little bit buggy on some operating systems.

    Edit: It is updated now with the fixed version of the function.
     
    Last edited: Sep 10, 2015
  8. TBardoux

    TBardoux

    Joined:
    Jul 20, 2015
    Posts:
    6
    Hi,
    I get these error on the last Unity 5 build :

    And don't know what exactly what I should do, delete the x86 files and keep the x86_64 since Unity 5 is 64 bits ?
     
  9. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
  10. TBardoux

    TBardoux

    Joined:
    Jul 20, 2015
    Posts:
    6
    Thank you, I fix the error 1 and 3, but the second is still here
    I don't know what to do, Unity does not prompt any possibility for x86_64 cpu for Android
     
  11. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. The Android x86_64 was zipped in the package for the future if unity will support x86_64 android devices. I don't know why you have it unzipped, I will look into it. You can safely delete it or zip it.

    Edit: you propably upgraded a unity4.x project to unity5.x. If you download with unity5 the package you should not see these errors.
     
  12. TBardoux

    TBardoux

    Joined:
    Jul 20, 2015
    Posts:
    6
    Yes it was an upgrade form 4.x to 5.x, I delete it thank you.
     
  13. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Update version 1.1

    iOS: added tvOS, watchOS and simulator plugins.

    Unity5.2: added WSA SDK10 NetCore support.

    (Delete the old Metro plugins folder, since it is replaced with a diferent naming scheme.)
     
  14. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Update version 1.2

    - Added WebGL support.

    - Linux, iOS, Android, MacOSX can treat now buffers as files. That means if you have a file in www.bytes you can perform operations directly on the buffer.
    (For Android this is very useful since you can decompress from Streaming Assets without copying to Persistent data path.)

    - all platforms: added support for fixed buffer operations to avoid memory allocations.

    - refactored the preprocessor directives to comply with Unity 5.3.

    - iOS: simulator plugin has now universal, i386 and x86_64 variations.

    - Thread safe corrections.
     
  15. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Update version 1.24/1.25

    - progress functions are the same on all platforms now. That introduced a small breaking code change. Instead of providing a referenced integer or float you provide a single item integer of float array. Removed deprecated iOS functions to get progress.

    - iOS: renamed some native functions to avoid collision with unity's libiphone lib.

    - all platforms: fixed an issue with decompressing of zip files containing the '__MACOSX' folder. The '__MACOSX' folder will be ignored along with files starting with '._' and files with 0 bytes size.


    Next update is on its way to solve Unicode issues with paths and filenames on Win and WSA plugins.
     
  16. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Update version 1.26

    - Winx86, Winx86_64 & WSA plugins: full unicode support on paths and filenames.
     
  17. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.27

    - Compatibility fixes for Windows Phone 8.1 and WSA8.1. Sdk8.1 should work out of the box now without the need to provide your own IO functions.
     
  18. Kea

    Kea

    Joined:
    Nov 12, 2012
    Posts:
    23
    Do your plugin support the iOS assembly in the Unity Cloud?

    Or I need to manually edit the Xcode project?
     
  19. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. I never tried to test this with the unity cloud.
    So I guess it is a try and see ...
     
  20. Kea

    Kea

    Joined:
    Nov 12, 2012
    Posts:
    23
    I try - cloud build work fine.
     
    elias_t likes this.
  21. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.28

    - Added bitcode supported plugins for iOS.
     
  22. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.3

    - added gzip support. Can operate on buffers with or without headers/footers.

    - added progress for individual file decompression.

    - Android, Linux, iOS, MacOSX got chmod support to set file permissions.

    - iOS: made the plugins much smaller in size.
     
  23. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.31

    iOS: hotfix to fix a GcHandle crash.
     
  24. hannahwilliams

    hannahwilliams

    Joined:
    May 25, 2014
    Posts:
    2
    Hi, I just bought your plugin and am experiencing an issue when I uncompress a file during a build (it's great in editor). It seems like the library isn't loading correctly (I've copied the log error below). I'm using OSX standalone. Any help would be appreciated!

    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.dylib
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.so
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.bundle
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.dylib
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.so
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.bundle
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.dylib
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.so
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw.bundle
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.dylib
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.so
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/./libzipw.bundle
    Fallback handler could not load library /Users/hw/Documents/test/CD/Builds/Tech Demo Mac x86/CD Universal.app/Contents/Frameworks/MonoEmbedRuntime/osx/libzipw

    Unhandled Exception: System.DllNotFoundException: libzipw
    at (wrapper managed-to-native) lzip:zipEX (string,string,intptr,intptr,int,intptr)
    at lzip.decompress_File (System.String zipArchive, System.String outPath, System.Int32[] progress, System.Byte[] FileBuffer, System.Int32[] proc) [0x00000] in <filename unknown>:0
     
  25. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi.

    It seems that you are using a x86 machine.

    The plugin is build as universal (for x86 and x86_64) and has a minimum target of osx 10.7.

    I have made some tests running a x86 build and it ran fine. However I don't have a x86 machine.

    I have build a x86 only plugin for osx and will send it to you over a private message.
     
  26. PlanetTimmy

    PlanetTimmy

    Joined:
    Mar 13, 2010
    Posts:
    117
    There appears to be no support for reading or writing from buffers in WebGL, which is basically the only thing I needed it for :(
     
  27. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. On Webgl you can compress/uncompress buffers.

    You cannot load a zip file in a buffer and treat this as a file.

    I tried to put it in but there was a limitation in the emscripten compiler....
     
  28. abhinandand91

    abhinandand91

    Joined:
    Dec 22, 2015
    Posts:
    6
    I want to use this plugin can you please mail me licence details of your plugin ?
     
  29. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Check your pm.
     
  30. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.32

    zip/Windows: better unicode support. Unity5.4 compatibility fix.
     
  31. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    is it possible to unzip a password protected file ?
     
  32. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I have an alpha version that runs on windows, but not for the rest of the platforms. So it could take a while.
     
  33. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.33

    gzip: Fixed Android issues and added a 2nd ungzip function.
     
  34. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.34

    Linux: fixed preprocessor directives for Unity5.4.x and up.
     
  35. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    update version 1.35

    All Platforms/gzip: Fixed a bug that was introduced in a previous update that had to with the outbuffer length. Now the gzip functions behave as intended.

    Windows: Now you can treat a zip file that is loaded in a byte buffer as a file.

    ios/gzip: updated the gzip functions.
     
  36. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Have problems on Android device:
    Zip-File gets downloaded but when trying to decrompress I get Zero in progress[0] and progress2[0].

    Maybe a problem with decompressing from Application.persistentDataPath ?

    The path is:
    /storage/emulated/0/Android/.../files/

    But with a filebrowser on the phone I see the directory "storage/emulated" is empty.
     
    Last edited: Oct 15, 2016
  37. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi.

    The plugin works ok and is fully tested.
    I just made a test on an Android6 device with Unity5.2.4.

    it looks more like a write permissions issue.

    Make sure you have write Access: external (SD-Card) set.
    Also make sure that you gave your device permission to write to the sd-card.
     
  38. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    version 1.36

    Windows: A small fix to the getTotalFiles function to allow to work correctly with FileBuffers
     
  39. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    version 1.38

    All platforms: added the delete_entry function to delete an entry in a zip file.

    All platforms: added the replace_entry function to replace an entry in a zip file(from a filepath or a buffer).

    (These 2 functions will not recompress the original archive. A tmp file is created where the compressed data of the other archives is copied and after that the deletion or replacement occurs.)
     
    Last edited: Dec 8, 2016
  40. alonsoGarrote

    alonsoGarrote

    Joined:
    Jun 23, 2012
    Posts:
    25
    Hi there,
    Im working on a level editor, I want to store level data into a string so it can be passed to a QR Code generator for easy share.
    Can I use this tool to "zip" the string so I can send more data on the same QR Code version?,
     
  41. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. Yes you can.

    Here is the instructions text file with all the included functions:
     

    Attached Files:

  42. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi. Elias

    Just bought and using it now.

    Is there function to replace zip entry using buffer instead?
    Currently I am doing something like :

    lzip.delete_entry(fileName, zipEntryName);
    lzip.buffer2File(0, fileName, zipEntryName, data, true);

    Surely this involves packing and unpacking zip file in between so if there is function to do this in one go, it should speed things a bit?

    What do you think?
     
  43. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Hi. Yes there are 2 replace_entry functions:

    replace_entry(string zipArchive, string arc_filename, string newFilePath, int level = 9);

    and

    replace_entry(string zipArchive, string arc_filename, byte[] newFileBuffer, int level = 9);

    The 2nd replace_entry function is the fastest you can get right now.

    I will make some experiments however if it can be sped up.
     
  44. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Hi I am sorry to not have mentioned this , but I am trying to use the tool in Windows 10 UWP platform. And the second API will not work on that platform as far as I understand.

    Having mentioned the UWP, does the tool internally uses Windows.Storage functions to access the files etc? I am pretty new to the UWP, but I think we can't normally access the files in normal Windows way for UWP apps. (even on Windows 10 desktop). Can you share a bit more info on this?
     
  45. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    You should be ok to run the lib on uwp as it is right now. I had reports from users running it on windows phone 8.1.

    As long as you use Application.PersistentDataPath there would be no issues.

    I just ran a test on windows 10 uwp desktop with success.
    I am updating now on win10 vs to update 3 to run a test on a windows 10 phone.

    But in any case if you are having any problems I can update some native IO functions to be more uwp friendly.
     
  46. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    I just made a test on a windows 10 phone with the latest vs 2015 tools and updates and it is working as intended.
    If you run on any issues message me.
     
  47. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Humm. Have you tried on building using IL2CPP ?

    It is the only one that I can use and it seems like lzip.entry2Buffer returns null...no matter what. It only seems to happen on running built one.
     
  48. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    It is a long time since I tested uwp il2cpp because it had so many issues with native plugins.
    I will retest today and get back to you.
     
  49. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Ok.

    I have made various compilations using vs2015 update3, unity 5.4.2 and it seems that it works correct.

    What versions do you use?

    It could be also that you are not passing the correct path of the zip entry to the function?
     
  50. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    My path is something like this.

    C:/Users/Saehoon/AppData/Local/Packages/Subterrain_w2mhztaywj74e/LocalState\Saves\SaveGame_Slot0.dat

    Does forward or backward slash matter?

    I verify the file before using lzip by File.Exist and it does find it.

    When I look inside the zip using 7zip , it all looks good.