/// <summary> /// 解压文件并返回解压后的文件字节数组 /// </summary> /// <param name="path">要解压的文件完全路径 例如: D:/Eclipse/configuration/zzzz.gz </param> /// 此方法返回解压后的文件字节数组 /// <returns></returns> public static byte[] DecompressFile(string path) { string tempFilePath = System.IO.Path.GetDirectoryName(path); if (tempFilePath != "") //如果解析出来的目录路径不为空 { if (!Directory.Exists(tempFilePath)) //判断是否存在 { try { Directory.CreateDirectory(path);//创建新路径 } catch (Exception e) { Debug.LogError($"路径格式错误{e.Message}"); return(null); } } } else { Debug.LogError("路径格式错误"); return(null); } string str = TestGZip.ReadGzipFromFile(path); byte[] bytes = System.Text.Encoding.Default.GetBytes(str); return(bytes); }
/// <summary> /// 亚索文件 /// </summary> /// <param name="bytes">要压缩文件的字节数组</param> /// <param name="path">压缩后的文件存储路径 完全路径,例如: D:/Eclipse/configuration/zzzz.gz </param> //注意!!!!!!! gzip的文件格式以.gz结尾 public static void CompressFile(byte[] bytes, string path) { string str = System.Text.Encoding.Default.GetString(bytes); string filePath = path; byte[] compressedBytes = TestGZip.WriteGzip(str); File.WriteAllBytes(filePath, compressedBytes); }