Untitled
unknown
plain_text
2 years ago
1.5 kB
5
Indexable
Never
public class GZipDecoder : MonoBehaviour { // The URL of the gzip-encoded image file private string imageUrl = "https://example.com/image.gz"; IEnumerator Start() { // Create a UnityWebRequest to download the gzip-encoded image file UnityWebRequest request = UnityWebRequest.Get(imageUrl); // Send the request and wait for the response yield return request.SendWebRequest(); // Check for errors if(request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError) { Debug.LogError(request.error); yield break; } // Get the gzip-encoded image data from the response byte[] gzipData = request.downloadHandler.data; // Create a MemoryStream to hold the decompressed image data MemoryStream memStream = new MemoryStream(); // Create a GZipStream to decompress the gzip-encoded image data GZipStream gzipStream = new GZipStream(new MemoryStream(gzipData), CompressionMode.Decompress); // Copy the decompressed image data to the MemoryStream gzipStream.CopyTo(memStream); // Get the decompressed image data as a byte array byte[] imageData = memStream.ToArray(); // Create a Texture2D from the decompressed image data Texture2D texture = new Texture2D(1, 1); texture.LoadImage(imageData); // Use the Texture2D in your application // ... } }