/// <summary> /// 开始解压缩 /// </summary> /// <param name="localFilePath"></param> /// <param name="buffer"></param> private void BeginDecompressExtract(string localFilePath, byte[] buffer) { try { using (var decompressor = new ZstdNet.Decompressor()) { var path = localFilePath; var bytes = decompressor.Unwrap(buffer); if (File.Exists(path)) { File.Delete(path); } File.WriteAllBytes(path, bytes); //下载文件中的MD5=未压缩时文件的MD5 DownloadFileMD5 = MD5.ComputeHashString(bytes); } } catch (Exception e) { NotiData data = new NotiData(NotiConst.DOWNLOAD_EXTRACT_FAILED, this.FileName, e.Message); if (File.Exists(localFilePath)) { File.Delete(localFilePath); } if (OnComplete != null) { OnComplete(data); //回调逻辑层 } } }
public void ExecuteThreadedWork() { SubFileMD5Dic = new Dictionary <string, string>(); try { FileMD5 = MD5.ComputeHashString(FileBytes); using (var decompressor = new ZstdNet.Decompressor()) { #if UNITY_IOS FileBytes = Crypto.Decode(FileBytes); #endif using (var ms = new MemoryStream(decompressor.Unwrap(FileBytes))) { using (var reader = new BinaryReader(ms)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { string abName = reader.ReadString(); int length = reader.ReadInt32(); var path = LocalPath + abName; string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var bytes = reader.ReadBytes(length); if (File.Exists(path)) { File.Delete(path); } File.WriteAllBytes(path, bytes); SubFileMD5Dic[abName] = MD5.ComputeHashString(bytes); } } } } } catch (Exception e) { var data = new NotiData(NotiConst.UPDATE_EXTRACT_FAILED, FileName, e.Message); if (OnComplete != null) { OnComplete(data); //回调逻辑层 } } FileBytes = null; }