title: Download a zip file using Groovy
body: <p>I need to download a zip file from a url using groovy.</p>
  
  <p>Test url: <a href="https://gist.github.com/daicham/5ac8461b8b49385244aa0977638c3420/archive/17a929502e6dda24d0ecfd5bb816c78a2bd5a088.zip" rel="nofollow noreferrer">https://gist.github.com/daicham/5ac8461b8b49385244aa0977638c3420/archive/17a929502e6dda24d0ecfd5bb816c78a2bd5a088.zip</a></p>
  
  <p>What I've done so far:</p>
  
  <pre><code>def static downloadArtifacts(url,filename) {
          new URL(url).openConnection().with { conn -&gt;
              conn.setRequestProperty("PRIVATE-TOKEN", "xxxx")
              url = conn.getHeaderField( "Location" )
              if( !url ) {
                  new File((String)filename ).withOutputStream { out -&gt;
                      conn.inputStream.with { inp -&gt;
                          out &lt;&lt; inp
                          inp.close()
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>But while opening the downloaded zip file I get an error "An error occurred while loading the archive".</p>
  
  <p>Any help is appreciated.</p>