public static void PKZipToLZ4() { string[] GUIDs = Selection.assetGUIDs; foreach (string guid in GUIDs) { try { string assetPath = AssetDatabase.GUIDToAssetPath(guid); TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath); MemoryStream memoryStream = new MemoryStream(); byte[] textBytes = textAsset.bytes; memoryStream.Write(textAsset.bytes, 0, textBytes.Length); memoryStream.Position = 0; ZipFile zip = ZipFile.Read(memoryStream); LZ4File lz4File = new LZ4File(); foreach (string entryFileName in zip.EntryFileNames) { ZipEntry entry = zip[entryFileName]; MemoryStream extractMemoryStream = new MemoryStream(); entry.Extract(extractMemoryStream); lz4File.AddEntry(entryFileName, extractMemoryStream.ToArray()); } string fileName = Path.GetFileName(assetPath); fileName = fileName.Replace(Path.GetExtension(fileName), String.Empty); FileStream saveFileStream = File.Create(assetPath.Replace(fileName, fileName + "LZ4")); lz4File.Save(saveFileStream); } catch (Exception exception) { Debug.LogException(exception); } } AssetDatabase.Refresh(); }
public static void CompressToLZ4() { string[] GUIDs = Selection.assetGUIDs; LZ4File lz4File = new LZ4File(); foreach (string guid in GUIDs) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); byte[] bytes = File.ReadAllBytes(assetPath); lz4File.AddEntry(Path.GetFileName(assetPath), bytes); } FileStream stream = File.Create("Assets/TestLZ4HC.bytes"); lz4File.Save(stream); AssetDatabase.Refresh(); }