private void TestLZ4() { for (int i = 0; i < 100; i++) { MemoryStream memoryStream = new MemoryStream(); byte[] textBytes = textAsset.bytes; memoryStream.Write(textAsset.bytes, 0, textBytes.Length); memoryStream.Position = 0; LZ4File lz4File = LZ4File.Read(memoryStream); foreach (string entryFileName in lz4File.EntryFileNames) { LZ4Entry entry = lz4File[entryFileName]; MemoryStream extractMemoryStream = new MemoryStream(); entry.Extract(extractMemoryStream); } } }
public static void DecompressLZ4() { string[] GUIDs = Selection.assetGUIDs; foreach (string guid in GUIDs) { try { string assetPath = AssetDatabase.GUIDToAssetPath(guid); TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath); if (textAsset == null) { continue; } string fileName = Path.GetFileName(assetPath); string extractDirectorName = fileName.Replace(Path.GetExtension(fileName), string.Empty); DirectoryInfo info = Directory.CreateDirectory(Path.Combine(Directory.GetParent(assetPath).FullName, extractDirectorName)); MemoryStream memoryStream = new MemoryStream(); byte[] textBytes = textAsset.bytes; memoryStream.Write(textAsset.bytes, 0, textBytes.Length); memoryStream.Position = 0; LZ4File lz4File = LZ4File.Read(memoryStream); foreach (string entryFileName in lz4File.EntryFileNames) { LZ4Entry entry = lz4File[entryFileName]; using (FileStream extractMemoryStream = File.Create(Path.Combine(info.FullName, entryFileName))) { entry.Extract(extractMemoryStream); extractMemoryStream.Close(); } } } catch (Exception exception) { Debug.LogException(exception); } } AssetDatabase.Refresh(); }