WWForm downlod ZIP file and extract with SharpZipLib

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 :slight_smile:

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

you don’t use wwwform for this.

you would use the .bytes field of WWW which you use to request and download the zip

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

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

Ah yes: WriteAllBytes may in fact be the way to go.

Awesome Dream.

/salute

import System.net then you can use WebClient.

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