public byte[] GetChunkCompressedBytes(Vector relativeChunkLocation) { // Sanity check if (locationTable is null || timestampTable is null) { return(null); } var chunkIndex = GetChunkTableIndex(relativeChunkLocation); var(offset, size) = locationTable.GetOffsetSizeAtIndex(chunkIndex); if (size == 0) { return(null); } Memory <byte> memAlloc = fileCache.Memory.Slice(offset, size); var chunkAllocation = new ChunkAllocation(memAlloc); return(chunkAllocation.GetChunkBytes()); }
public async Task <bool> InitializeAsync() { if (!File.Exists(filePath)) { await InitializeNewFileAsync(); } try { regionFileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { return(false); } // Load file into memory await regionFileStream.ReadAsync(fileCache.Memory); regionFileStream.Seek(0, SeekOrigin.Begin); locationTable = new RegionFileHeaderTable(fileCache.Memory.Slice(0, tableSize)); timestampTable = new RegionFileHeaderTable(fileCache.Memory.Slice(tableSize, tableSize)); // Determine end of all allocations/next available allocation nextAvailableOffset = 8192; for (int x = 0; x < cubicRegionSize; x++) { for (int z = 0; z < cubicRegionSize; z++) { var tableIndex = GetChunkTableIndex(new Vector(x, 0, z)); var(offset, size) = locationTable.GetOffsetSizeAtIndex(tableIndex); if (size == 0) { continue; } if (offset + size > nextAvailableOffset) { nextAvailableOffset = offset + size; } } } return(true); }