コード例 #1
0
ファイル: FlatFileCache.cs プロジェクト: whymidnight/NetScape
        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());
        }
コード例 #2
0
        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));
        }