using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace System.Fire.Container { public partial class ContainerList { public byte[] ReadBytes(int FileIndex) { return ReadBytes(this._files[FileIndex]); } public byte[] ReadBytes(ContainerFile File) { return ReadBytes(File, 0, File.Size); } // --- public byte[] ReadBytes(int FileIndex, long StartPos) { return ReadBytes(this._files[FileIndex], StartPos); } public byte[] ReadBytes(ContainerFile File, long StartPos) { return ReadBytes(File, StartPos, File.Size - StartPos); } // --- public byte[] ReadBytes(int FileIndex, long StartPos, long Length) { return this.ReadBytes(this._files[FileIndex], StartPos, Length); } public byte[] ReadBytes(ContainerFile File, long StartPos, long Length) { long len = Length; if (len > File.Size - StartPos) len = File.Size - StartPos; byte[] res = new byte[0]; System.Diagnostics.Debug.WriteLine("ReadBytes 1: " + StartPos + " | " + Length + " | " + len); for (int i = 0, c = File.NumChunks; i < c; i++) { int containerSize = this.GetContainerLenFromChunk(File.ChunkPos, i); long xStart = Math.Max(0, StartPos); System.Diagnostics.Debug.WriteLine("ReadBytes 2: " + i + " | " + xStart + " | " + containerSize); if(StartPos <= containerSize) { int bytesToReadFromContainer = (int)Math.Min(len, containerSize - StartPos); byte[] b = this.ReadChunk(File.ChunkPos, i).Skip((int)xStart).Take(bytesToReadFromContainer).ToArray(); System.Diagnostics.Debug.WriteLine("ReadBytes X: " + xStart + " | " + bytesToReadFromContainer + " | " + b.Length); res.Concat(b); StartPos -= bytesToReadFromContainer; len -= b.Length; } else { StartPos -= containerSize; } if (len <= 0) break; } return res; } } }