x


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!

more ▼

asked Mar 14 '11 at 11:27 PM

Dave 10 gravatar image

Dave 10
1 4 4 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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!
more ▼

answered Mar 14 '11 at 11:36 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

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!

Mar 14 '11 at 11:48 PM Dave 10

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.

Mar 15 '11 at 12:15 AM Statement ♦♦

If your SharpZipLib support a stream to do the extracting you can just create a new MemoryStream.

Mar 15 '11 at 12:17 AM Statement ♦♦

Create a new MemoryStream 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

Mar 15 '11 at 12:21 AM Statement ♦♦

^ Instead of loading with WebClient, just do as in the answer and let data be a MemoryStream. Create the stream as such var data = new MemoryStream(bytes);

Mar 15 '11 at 12:22 AM Statement ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x437
x242
x195
x134
x16

asked: Mar 14 '11 at 11:27 PM

Seen: 1433 times

Last Updated: Mar 14 '11 at 11:27 PM