From 2b57c001a8670a580566d7be2209ebb281bbb0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Gisn=C3=A5s?= Date: Fri, 17 Jun 2022 17:03:44 +0200 Subject: [PATCH] Support Chunked Transfer-Encoding --- cloudfoundry/managers/bits/bitsmanager.go | 31 +++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/cloudfoundry/managers/bits/bitsmanager.go b/cloudfoundry/managers/bits/bitsmanager.go index 3fddbb636..d94eb795e 100644 --- a/cloudfoundry/managers/bits/bitsmanager.go +++ b/cloudfoundry/managers/bits/bitsmanager.go @@ -321,11 +321,32 @@ func (m BitsManager) RetrieveZip(path string) (ZipFile, error) { baseName = params["filename"] } } - return ZipFile{ - r: resp.Body, - baseName: baseName, - filesize: fileSize, - }, nil + if fileSize > 0 { + return ZipFile{ + r: resp.Body, + baseName: baseName, + filesize: fileSize, + }, nil + } else { + tempFile, err := ioutil.TempFile("", "") + if err != nil { + return ZipFile{}, err + } + defer os.Remove(tempFile.Name()) + fileSize, err := io.Copy(tempFile, resp.Body) + if err != nil { + return ZipFile{}, err + } + _, err = tempFile.Seek(0, 0) + if err != nil { + return ZipFile{}, err + } + return ZipFile{ + r: tempFile, + baseName: baseName, + filesize: fileSize, + }, nil + } } f, err := os.Open(path) if err != nil {