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:

  1. Open a terminal.
  2. 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.

  3. 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.

  4. 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.

  5. Use --compressed for automatic compression handling.
    $ curl --compressed "https://www.example.com/data"

    --compressed simplifies adding necessary headers and decoding responses.

Discuss the article:

Comment anonymously. Login not required.