Skip to content

Instantly share code, notes, and snippets.

@sunny352
Created March 17, 2017 09:01
Show Gist options
  • Save sunny352/2ba8331644fd8dfeacbdbaae119c61ab to your computer and use it in GitHub Desktop.
Save sunny352/2ba8331644fd8dfeacbdbaae119c61ab to your computer and use it in GitHub Desktop.
Zip压缩,需要UniRx和SharpZipLib支持
using ICSharpCode.SharpZipLib.Zip;
using System.Collections;
using UniRx;
using UnityEngine;
public static class ZipUtil
{
public static IEnumerator Create(string name)
{
string pakPath = string.Format("{0}/{1}.pak", Application.temporaryCachePath, name);
string srcPath = string.Format("{0}/{1}", Application.persistentDataPath, name);
return Observable.Start(() =>
{
FastZip fastZip = new FastZip();
fastZip.CreateZip(pakPath, srcPath, true, null);
return Unit.Default;
}).ObserveOnMainThread().ToYieldInstruction();
}
public static IEnumerator Extract(string name)
{
string pakPath = string.Format("{0}/{1}.pak", Application.temporaryCachePath, name);
string srcPath = string.Format("{0}/{1}", Application.persistentDataPath, name);
return Observable.Start(() =>
{
FastZip fastZip = new FastZip();
fastZip.ExtractZip(pakPath, srcPath, string.Empty);
return Unit.Default;
}).ObserveOnMainThread().ToYieldInstruction();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment