- Home /
Saving Local Data through WWW
I know this topic has been touched on a couple of times, but I'm still unclear of the exact answer (there's a topic fairly close but doesn't quite address it).
I have a constantly changing remote zip file that I want to download, then take the contents and unzip it using SharpZipLib (which I have working with a local file), and use the contents of the zip file. Is there a way to do this (or a library already available) either using the WWW lib, the WebClient lib, or even through some sort of php mechanism (but then would the unity web player have access to that file)? Or am I stuck with having to stream the content in and working with it that way?
Thanks in advance!
Answer by Statement · Mar 14, 2011 at 11:36 PM
If you look at the source code of ExportVisualStudio, there's a section that deals with downloading a zip file off the web using WWW.
Basically I think you should be able to do this:
WWW www = new WWW(url);
yield return www; // Wait for it to download, make the calling function a co-routine.
byte[] bytes = www.bytes; // Here you go!
Interesting, and thanks for the quick response. I'm very familiar with downloading via www and obtaining www.bytes, but I'm attempting to work with the resultant .zip file locally as a saved file (through SharpZipLib), so I'm hoping to save the www.bytes to disk. I don't have anything written to deal with the stream of the .zip code unless it's been opened by File.OpenRead first. I have pro, btw.
Thanks!
Well if you need to save it to disk and you're not using a web player, then you can just call System.IO.File.WriteAllBytes to write the bytes array to a file in one call.
If your SharpZipLib support a stream to do the extracting you can just create a new $$anonymous$$emoryStream.
Create a new $$anonymous$$emoryStream and set the contents to the bytes buffer, and follow this sample? http://wiki.sharpdevelop.net/SharpZipLib-Zip-Samples.ashx#Unpack_a_zip_using_ZipInputStream_eg_for_Unseekable_input_streams_5
^ Ins$$anonymous$$d of loading with WebClient, just do as in the answer and let data be a $$anonymous$$emoryStream. Create the stream as such var data = new $$anonymous$$emoryStream(bytes);