What is the difference between Encryption and Compression?

Data compression is the process of removing unneeded characters and using algorithms or formulas to reference data already seen, so as to cut down on the size of data being transferred. Compression and encryption over a connection go hand in hand, but which of these methods should come first? Technically, neither should be done. Encrypting data before compression can lead to a number of issues, including compression not being able to reduce the size of the message due to encryption destroying any patterns in the data. Compression then encryption is the better method if encryption and compression must be used, but if an attacker controls a portion of the plaintext being compressed and has access to the ciphertext, then the plaintext can be deduced by the attacker.