Download compression uses gzip or deflate to reduce data size and accelerate transfers. Many servers return compressed content if the client indicates support via the Accept-Encoding header.
With cURL, specifying Accept-Encoding or using --compressed requests compressed data and decompresses it upon arrival. This improves efficiency, especially when handling large HTTP responses.
Integrating compression into cURL workflows conserves bandwidth and enhances performance. Applying --compressed automates negotiations, simplifying efficient data retrieval.
Steps to use download compression in cURL:
- Open a terminal.
- Request compressed data using Accept-Encoding.
$ curl --header "Accept-Encoding: gzip, deflate" "https://www.example.com/data"
The server returns compressed data, automatically decompressed by cURL.
- Save the decompressed output to a file.
$ curl --header "Accept-Encoding: gzip, deflate" "https://www.example.com/data" --output data.json
The output file is stored uncompressed.
- Optionally save compressed data and decompress manually.
$ curl --header "Accept-Encoding: gzip" "https://www.example.com/data" --output data.gz $ gunzip data.gz
Manual decompression offers flexibility.
- Use --compressed for automatic compression handling.
$ curl --compressed "https://www.example.com/data"
--compressed simplifies adding necessary headers and decoding responses.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.