public string ReceiveFile(string fileName) { var header = networkStreamHandler.Read(Header.GetLength()); var fileNameSize = BitConverter.ToInt32(header, 0); var fileSize = BitConverter.ToInt64(header, Specification.FixedFileNameLength); var originalName = Encoding.UTF8.GetString(networkStreamHandler.Read(fileNameSize)); var dividedName = originalName.Split('.'); var extension = dividedName[dividedName.Length - 1]; fileName = fileName + "." + extension; long parts = SpecificationHelper.GetParts(fileSize); long offset = 0; long currentPart = 1; while (fileSize > offset) { byte[] data; if (currentPart == parts) { var lastPartSize = (int)(fileSize - offset); data = networkStreamHandler.Read(lastPartSize); offset += lastPartSize; } else { data = networkStreamHandler.Read(Specification.MaxPacketSize); offset += Specification.MaxPacketSize; } fileStreamHandler.Write(fileName, data); currentPart++; } return(fileName); }
public string ReceiveFile() { var header = networkStreamHandler.Read(FileHeader.GetLength()); var fileNameSize = BitConverter.ToInt32(header, 0); var fileSize = BitConverter.ToInt64(header, Specification.FixedFileNameLength); var fileName = Encoding.UTF8.GetString(networkStreamHandler.Read(fileNameSize)); long parts = SpecificationHelper.GetParts(fileSize); long offset = 0; long currentPart = 1; while (fileSize > offset) { byte[] data; if (currentPart == parts) { var lastPartSize = (int)(fileSize - offset); data = networkStreamHandler.Read(lastPartSize); offset += lastPartSize; } else { data = networkStreamHandler.Read(Specification.MaxPacketSize); offset += Specification.MaxPacketSize; } FileStreamHandler.Write(fileName, data); currentPart++; } return(fileName); }