Unity Community


Page 1 of 2 12 LastLast
Results 1 to 20 of 26

  1. Location
    The Netherlands
    Posts
    5

    Cant use GZipStream from C# behaviours

    When trying to use GZipStream from a c# behaviour i get an exeption (This occurs only on my mac box)


    Code:  
    1. System.DllNotFoundException: MonoPosixHelper
    2.   at (wrapper managed-to-native) System.IO.Compression.DeflateStream:create_z_stream (System.IO.Compression.CompressionMode,bool)
    3.   at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip) [0x00000]
    4.   at (wrapper remoting-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode,bool,bool)
    5.   at System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen) [0x00000]
    6.   at System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode) [0x00000]
    7.   at (wrapper remoting-invoke-with-check) System.IO.Compression.GZipStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode)
    8.   at GZIPDecompressor.Decompress (System.Byte[] data) [0x00042] in /Users/peterbjornx/runescape client 3/runescape client/assets/runescape scripts/cache/GZIPDecompressor.cs:20

  2. Unity tech writer

    Location
    Blackpool, United Kingdom
    Posts
    8,696
    Unity is limited to the classes that come with the Mono runtime - System.IO.Compression isn't among these.
    I'm wired to the world... that's how I... know... everything...


  3. Location
    London
    Posts
    1,098
    With a pro license is it possible to drop in a mono dll that will deal with gzip compression?


  4. Location
    Zürich, Switzerland
    Posts
    26,572
    no need for pro, .net dlls always work

    unsure if this is possible for framework dlls though (as they will cause collisions)
    also the dll must not use namespaces cut from the webplayer at all


  5. Location
    London
    Posts
    1,098
    I've got this working for the mac standalone and it also appears to work for the webplayer.

    I've used the SharpZipLib .NET source and compiled it with mono.

    http://www.icsharpcode.net/OpenSource/SharpZipLib/

    Then used this code from the Code Project to compress and uncompress a string.

    http://www.codeproject.com/KB/dotnet/mscompression.aspx

    Code:  
    1. using System;
    2. using System.IO;
    3. using System.Text;
    4. using ICSharpCode.SharpZipLib.BZip2;
    5.  
    6. [System.Serializable]
    7. public struct Zipper
    8. {
    9.     public static string ZipString(string sBuffer)
    10.     {
    11.         MemoryStream m_msBZip2 = null;
    12.         BZip2OutputStream m_osBZip2 = null;
    13.         string result;
    14.         try
    15.         {
    16.             m_msBZip2 = new MemoryStream();
    17.             Int32 size = sBuffer.Length;
    18.             // Prepend the compressed data with the length of the uncompressed data (firs 4 bytes)
    19.             //
    20.             using (BinaryWriter writer = new BinaryWriter(m_msBZip2, System.Text.Encoding.ASCII))
    21.             {
    22.                 writer.Write( size );
    23.                
    24.                 m_osBZip2 = new BZip2OutputStream(m_msBZip2);
    25.                 m_osBZip2.Write(Encoding.ASCII.GetBytes(sBuffer), 0, sBuffer.Length);
    26.                
    27.                 m_osBZip2.Close();
    28.                 result = Convert.ToBase64String(m_msBZip2.ToArray());
    29.                 m_msBZip2.Close();
    30.                
    31.                 writer.Close();
    32.             }
    33.         }
    34.         finally
    35.         {
    36.             if (m_osBZip2 != null)
    37.             {
    38.                 m_osBZip2.Dispose();
    39.             }
    40.             if (m_msBZip2 != null)
    41.             {
    42.                 m_msBZip2.Dispose();
    43.             }
    44.         }
    45.         return result;
    46.     }
    47.  
    48.     public static string UnzipString(string compbytes)
    49.     {
    50.         string result;
    51.         MemoryStream m_msBZip2 = null;
    52.         BZip2InputStream m_isBZip2 = null;
    53.         try
    54.         {
    55.             m_msBZip2 = new MemoryStream(Convert.FromBase64String(compbytes));
    56.             // read final uncompressed string size stored in first 4 bytes
    57.             //
    58.             using (BinaryReader reader = new BinaryReader(m_msBZip2, System.Text.Encoding.ASCII))
    59.             {
    60.                 Int32 size = reader.ReadInt32();
    61.                
    62.                 m_isBZip2 = new BZip2InputStream(m_msBZip2);
    63.                 byte[] bytesUncompressed = new byte[size];
    64.                 m_isBZip2.Read(bytesUncompressed, 0, bytesUncompressed.Length);
    65.                 m_isBZip2.Close();
    66.                 m_msBZip2.Close();
    67.                
    68.                 result = Encoding.ASCII.GetString(bytesUncompressed);
    69.                
    70.                 reader.Close();
    71.             }
    72.         }
    73.         finally
    74.         {
    75.             if (m_isBZip2 != null)
    76.             {
    77.                 m_isBZip2.Dispose();
    78.             }
    79.             if (m_msBZip2 != null)
    80.             {
    81.                 m_msBZip2.Dispose();
    82.             }
    83.         }
    84.         return result;
    85.     }
    86. }
    Attached Files


  6. Location
    FL - USA
    Posts
    454
    Hello monark

    Is it possible to call your functions from Javascript?

    Thanks
    Andres Martinez
    baKno Games
    www.bakno.com


  7. Location
    FL - USA
    Posts
    454
    I figured it out.

    Thank you for sharing your code!

    It works great.
    Andres Martinez
    baKno Games
    www.bakno.com


  8. Location
    London
    Posts
    1,098
    For others who pass this way, yes it is....


  9. Location
    FL - USA
    Posts
    454
    Have you ever tried to make it work on a Windows build?
    Andres Martinez
    baKno Games
    www.bakno.com


  10. Location
    London
    Posts
    1,098
    yup, seems to be fine in my tests so far, have you found otherwise?


  11. Location
    FL - USA
    Posts
    454
    I have not tried that yet. But since the DLL is necessary within the Plugins folder I thought a similar file would be necessary for the Windows build.
    Andres Martinez
    baKno Games
    www.bakno.com


  12. Location
    London
    Posts
    1,098
    I think it just bundles it all up for you automatically as it's a mono dll, I didn't do anything special to include it in the windows standalone version I tried.


  13. Location
    Montpellier , FRANCE
    Posts
    31
    Hi , could someone explain how to use this with JavaScript ?


  14. Location
    London
    Posts
    1,098
    Just download the dll I included with my original post and include it in your assets folder. I put it in a sub folder called "Plugins" but I don't think it matters where you put it.
    Then in javascript you should be free to use the ZipString and UnzipString functions any where you like just as you would any builtin function.

    e.g

    Code:  
    1. var myString : String = "Hello world";
    2.  
    3. var myZippedString : String = Zipper.ZipString(myString);
    4.  
    5. var myUnZippedString : String = Zipper.UnzipString(myZippedString);


  15. Location
    Montpellier , FRANCE
    Posts
    31
    Hum , it should work just like that ?

    Because I get this error :

    "Unknown identifier : 'Zippper' "


  16. Location
    London
    Posts
    1,098
    Sounds like it's not picking up the dll properly.

    Do you get any compile error messages that relate to Zipper other than the one you posted?

    Unless it's cos I compiled it on a mac and you are on windows?


  17. Location
    Co Donegal, Ireland
    Posts
    1,066
    @MatOfLink - Have you included Monark's code from further up the thread? Zipper is defined in there.

    On a side note, this is good stuff and I will try and use it within a project.

    Best Regards,
    Matt.


  18. Location
    London
    Posts
    1,098
    Oh yeah, doh! you need that bit of code too. I forgot about that the dll is the compressor but it needs that wrapper code too. Just make a C Sharp script copy that code into it and put it somewhere like "Assets/Pro Standard Assets"


  19. Location
    Montpellier , FRANCE
    Posts
    31
    Oh damn, I've been refreshing page 1 since I posted so I hadn't seen your answer yet xD

    So, thank you, it works perfectly

    [Edit]

    Ok it works with String.
    Now here is my new problem :

    I get a file (which is zipped) using WWW. How should I use Zipper to decompress the data within it ?
    I don't want to unzip the file physically, just get the data and decompress it in order to read it.


  20. Location
    Zürich, Switzerland
    Posts
    26,572
    if you use above Zipper, just through UnzipString with the www.data

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •