Search Unity

WWForm downlod ZIP file and extract with SharpZipLib

Discussion in 'Scripting' started by Julian-Glenn, Sep 15, 2010.

  1. Julian-Glenn

    Julian-Glenn

    Joined:
    Jul 23, 2010
    Posts:
    97
    Hi all,

    I'm a little lost and maybe in over my artsyhead a little.

    I need to fetch a ZIP file from a webserver and then uncompress it from within a Unity app. I have been using SharpZipLib and uncompressing a local .zip file no problem by passing in a full path to the local .zip file. But I guess what I need to do is read in the bytes passed in by the wwwform and then somehow reassemble them into a local .zip file. Here's where I get lost.

    I'm no coding guru and get a bit confused dealing with these meta-physical things like a byte[] array :)

    Has anyone done this or can at least can point me to an example of creating a zip file from the results of a wwwform get operation or I guess a byte[] array in general.

    ty,
    /Julian
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you don't use wwwform for this.

    you would use the .bytes field of WWW which you use to request and download the zip
     
  3. Julian-Glenn

    Julian-Glenn

    Joined:
    Jul 23, 2010
    Posts:
    97
    Sorry that's what I am using. I actually got it to work partially using a function GetViaZipInput from the examples here: http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx

    problem is if the Zip file has an internal Folder/Directory structure it creates the first folder but then barfs out with a UnauthorizedAccessException error on the folder it just created.

    /cheers
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Assuming you are on a standalone player (in webplayer you can't), you can use System.IO.File.WriteAllBytes and store the zip to disk to decompress it.

    just ensure that you store it in the users temp not the game directory as that might be in a place where you have no write access at all
     
  5. Julian-Glenn

    Julian-Glenn

    Joined:
    Jul 23, 2010
    Posts:
    97
    Ah yes: WriteAllBytes may in fact be the way to go.

    Awesome Dream.

    /salute
     
  6. edmiester777

    edmiester777

    Joined:
    Nov 18, 2013
    Posts:
    1
    import System.net then you can use WebClient.

    new WebClient().downloadFile(new Uri("http://www.example.com/example.zip"), "C://example.zip");