Skip to content

Instantly share code, notes, and snippets.

@r2d2rigo
r2d2rigo / ExtractZipFile.cs
Last active August 18, 2021 10:05
Using SharpZipLib to extract zip files from Unity in a coroutine-friendly way
// This sample function uses SharpZipLib (http://icsharpcode.github.io/SharpZipLib/) to extract
// a zip file without blocking Unity's main thread. Remember to call it with StartCoroutine().
// Byte data is passed so a MemoryStream object is created inside the function to prevent it
// from being reclaimed by the garbage collector.
public IEnumerator ExtractZipFile(byte[] zipFileData, string targetDirectory, int bufferSize = 256 * 1024)
{
Directory.CreateDirectory(targetDirectory);
using (MemoryStream fileStream = new MemoryStream())
@r2d2rigo
r2d2rigo / AsyncHttpWebRequest.cs
Last active March 14, 2023 07:44
An elegant way of asynchronously requesting web sites on Windows Phone.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
public class AsyncHttpWebRequest
{
private HttpWebRequest webRequest;