Writing An Asset Bundle To Disk

Yes, it’s another odd one :stuck_out_tongue: I’ve been trying to find a way to write a downloaded asset bundle to disk for later use. Using the following code, however, results in 1 byte files which obviously means something is going haywire:

		string url;
		int count = 0;
		
		foreach(string entry in buildFiles)
		{
			Debug.Log(entry + "Downloading...");
			url = host + "resources/" + entry;
			www = new WWW(url);
			yield return www;

			Debug.Log(entry + "Done!");
			Debug.Log(count);
			Debug.Log(www.assetBundle.mainAsset);
			assetBundles[count] = www.assetBundle;
			
			FileStream fs = new FileStream(folderPath + "/" + entry, FileMode.OpenOrCreate, FileAccess.Write);
                        BinaryWriter bw = new BinaryWriter(fs);
                
                        bw.Write(www.assetBundle);
                
                        bw.Close();

                        fs.Close();
			count++;
		}

What would be the proper way to write an assetBundle downloaded through a WWW object to disk so it can be loaded from disk later?

Oy. The word “Duh” comes to mind now that I take a second look. “www.assetBundle” is useful for dealing with unpacking it and the like, but the actual information making up the file is in “www.bytes”. Or at least it’s saving something now and the file sizes are about where I was expecting them. Whether what it saves is a valid asset bundle remains to be seen :stuck_out_tongue: