Compression
Compression is reducing the size of a file. This is done to reduce the amount of storage space it takes up or to reduce the bandwidth when sending a file. There are 2 types of compression:
- Lossless Compression:
- A compression algorithm is used to reduces the file size without permanently removing any data
- Repeated patterns in the file are identified and indexed
- The data is replaced with the index and positions stored
- The number of times the pattern appears is also stored
- Techniques like run-length encoding (RLE) and Huffman encoding are used
- RLE replaces sequences of repeated characters with a code that represents the character and the number of times it is repeated
- Huffman encoding replaces frequently used characters with shorter codes and less frequently used characters with longer codes
- Lossy Compression:
- Lossy compression reduces the file size by permanently removing some data from the file
- This method is often used for images and audio files where minor details or data can be removed without significantly impacting the quality
- Techniques like downsampling, reducing resolution or colour depth, and reducing the sample rate or resolution are used for lossy compression
- The amount of data removed depends on the level of compression selected and can impact the quality of the final file
- Overall:
- Compression is necessary to reduce the size of large files for storage, transmission, and faster processing
- The choice between lossy and lossless compression methods depends on the type of file and its intended use
- Lossy compression is generally used for media files where minor data loss is acceptable while lossless compression is used for text, code, and archival purposes