Lz4ArchiveEntry.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.IO;
  2. using System.Text;
  3. namespace SongCore.Arcache
  4. {
  5. public class Lz4ArchiveEntry
  6. {
  7. public string FileName { get; set; }
  8. public long OriginalSize { get; set; }
  9. internal long Offset { get; set; }
  10. internal long CompressedSize { get; set; }
  11. internal void WriteToIndex(Stream stream)
  12. {
  13. using var bw = new BinaryWriter(stream, Encoding.UTF8, true);
  14. var nameBytes = Encoding.UTF8.GetBytes(FileName);
  15. bw.Write((short)nameBytes.Length);
  16. bw.Write(nameBytes);
  17. bw.Write(Offset);
  18. bw.Write(CompressedSize);
  19. bw.Write(OriginalSize);
  20. }
  21. internal void ReadFromStream(Stream stream)
  22. {
  23. using var br = new BinaryReader(stream, Encoding.UTF8, true);
  24. var nameByteCount = br.ReadInt16();
  25. var nameBytes = br.ReadBytes(nameByteCount);
  26. FileName = Encoding.UTF8.GetString(nameBytes);
  27. Offset = br.ReadInt64();
  28. CompressedSize = br.ReadInt64();
  29. OriginalSize = br.ReadInt64();
  30. }
  31. }
  32. }