private void ReceiveFileWithStreams(long fileSize, string fileName) { long fileParts = ProtocolConstants.CalculateFileParts(fileSize); long offset = 0; long currentPart = 1; while (fileSize > offset) { var packetSize = currentPart == fileParts ? (int)(fileSize - offset) : ProtocolConstants.MaxPacketSize; var data = _communication.Read(packetSize); offset += packetSize; _fileStreamHandler.Write(fileName, data); currentPart++; } }
private void SendFileWithStream(long fileSize, string path) { var fileParts = ProtocolConstants.CalculateFileParts(fileSize); long offset = 0; long currentPart = 1; while (fileSize > offset) { var packetSize = currentPart == fileParts ? (int)(fileSize - offset) : ProtocolConstants.MaxPacketSize; var data = _fileStreamHandler.Read(path, offset, packetSize); offset += packetSize; _communication.Write(data); currentPart++; } }