protected override BinaryFile GetBinaryFile(CacheFileInfo fileInfo) { // Single file if (!fileInfo.UsesEntries) { return(new BinaryFile { Info = fileInfo, Data = File.ReadAllBytes(this.GetExistingFilePaths(fileInfo.Index, fileInfo.FileId.Value).First()) }); } // Entries var entryFile = new EntryFile { Info = fileInfo }; foreach (var existingEntryPath in this.GetExistingEntryPaths(fileInfo.Index, fileInfo.FileId.Value)) { entryFile.AddEntry(existingEntryPath.Key, File.ReadAllBytes(existingEntryPath.Value)); } // TODO: Return EntryFile directly so it doesn't have to be needlessly encoded return(entryFile.ToBinaryFile()); }
public void TestEncodeDecodeWithEmptyEntries() { var entryData = new byte[] { 0, 12, 123, 8 }; var entryFile = new EntryFile { Info = new CacheFileInfo { EntryInfo = new SortedDictionary <int, CacheFileEntryInfo> { { 5, new CacheFileEntryInfo { EntryId = 5 } } } } }; entryFile.AddEntry(5, entryData); var binaryFile = entryFile.ToBinaryFile(); var decodedEntryFile = new EntryFile(); decodedEntryFile.FromBinaryFile(binaryFile); Assert.True(entryData.SequenceEqual(decodedEntryFile.GetEntry <BinaryFile>(5).Data)); }