public async ValueTask PersistMemoryChunksAsync(bool isInitialVersion) { var memoryChunksToPersist = GetUnpersistedMemoryChunks(); long offset = 0; string pathForSingleBlob = ContainedInSingleBlob ? GetPathForMemoryChunk(0) : null; if (ContainedInSingleBlob) { if (isInitialVersion) { if (BlobManager.Exists(pathForSingleBlob)) { BlobManager.Delete(pathForSingleBlob); } offset = 0; } else { offset = BlobManager.GetLength(pathForSingleBlob); } BlobManager.OpenForWriting(pathForSingleBlob); } foreach (var memoryChunkToPersist in memoryChunksToPersist) { await memoryChunkToPersist.LoadMemoryAsync(); int memoryBlockID = memoryChunkToPersist.MemoryBlockID; string path = GetPathForMemoryChunk(memoryBlockID); if (ContainedInSingleBlob) { await BlobManager.AppendAsync(path, memoryChunkToPersist.MemoryAsLoaded.ReadOnlyMemory); UpdateLoadingOffset(memoryChunkToPersist.MemoryBlockID, offset); offset += memoryChunkToPersist.LoadingInfo.PreTruncationLength; } else { BlobManager.Write(path, memoryChunkToPersist.MemoryAsLoaded.ReadOnlyMemory); } memoryChunkToPersist.IsPersisted = true; OnMemoryChunkPersisted(memoryBlockID); } if (ContainedInSingleBlob) { BlobManager.CloseAfterWriting(pathForSingleBlob); } }