curlgitlabpipeunzip

Pipe curl output into unzip


I'm building a CI/CD script in GitLab and want to unzip a curl output in the current dir by piping the curl output into unzip.

All the answers I could find suggests wget, tar or other tools.

Here is what I have:

curl -L "$URL" | unzip - -d ./output

Result is "Can not find output.zip so obviously unzip doesen't understand the dash placeholder when piping.


Solution

  • It looks like unzip doesn't support unzipping from a streaming pipe.

    If you have access to ditto or bsdtar, you can use those.

    curl -sSL "https://..." | ditto -x -k - $outdir
    curl -sSL "https://..." | bsdtar -xvf- -C $outdir
    

    If you need to use unzip, you can simply download the zip into a temporary file and extract it from there.

    curl -sSL "https://..." -o archive.zip
    unzip archive.zip -d $outdir
    rm archive.zip