/// <summary> /// Gets the updated chunks. /// </summary> public IEnumerable <DifferenceChunkDto> GetUpdatedChunks(string fileName, IEnumerable <CachedChunkDto> cacheChunks) { string downloadFilePath = Path.Combine(CommonConstants.ServerFilesLocation, $"{fileName}"); List <Chunk> chunks = RabinKarpAlgorithm.Slice(File.ReadAllBytes(downloadFilePath)); return(ChunkDifferentiator.GetUpdatedChunks(cacheChunks.Select(CachedChunkDtoMapper.Map).ToList(), chunks).Select(DifferenceChunkDtoMapper.Map)); }
private async Task <Stream> UpdateCachedFile(string fileName, byte[] cachedFileContent, ServerServiceClient serverServiceClient, string cachedFileLocation) { List <Chunk> cachedChunks = RabinKarpAlgorithm.Slice(cachedFileContent); DifferenceChunkDto[] differenceChunkDtos = await serverServiceClient.GetUpdatedChunksAsync(fileName, cachedChunks.Select(CachedChunkDtoMapper.Map).ToArray()); byte[] newFileContent = ConstructContentOfTheUpdateFile(differenceChunkDtos, cachedChunks, fileName); System.IO.File.WriteAllBytes(cachedFileLocation, newFileContent); return(new MemoryStream(newFileContent)); }