diff options
| author | Stefan Majewsky <stefan.majewsky@sap.com> | 2022-10-28 16:06:40 +0200 |
|---|---|---|
| committer | Stefan Majewsky <stefan.majewsky@sap.com> | 2022-10-28 16:06:40 +0200 |
| commit | 90dd519a948d06738479c04d331f28dfab99315c (patch) | |
| tree | d4a9914cb73be3dbe9438b012a08408d79bdb7c9 /download.go | |
| parent | fd6e57b6239655722884a49a86be0f051cc32bde (diff) | |
| parent | 5cf9b60d2ded95d29827389a1a5901f1068d4337 (diff) | |
| download | go-schwift-90dd519a948d06738479c04d331f28dfab99315c.tar.gz | |
Merge remote-tracking branch 'SuperSandro2000:sha2'
Diffstat (limited to 'download.go')
| -rw-r--r-- | download.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/download.go b/download.go index dfd9a07..8367f3d 100644 --- a/download.go +++ b/download.go @@ -20,27 +20,26 @@ package schwift import ( "io" - "io/ioutil" ) -//DownloadedObject is returned by Object.Download(). It wraps the io.ReadCloser -//from http.Response.Body with convenience methods for collecting the contents -//into a byte slice or string. +// DownloadedObject is returned by Object.Download(). It wraps the io.ReadCloser +// from http.Response.Body with convenience methods for collecting the contents +// into a byte slice or string. // // var obj *swift.Object // // //Do NOT do this! // reader, err := obj.Download(nil).AsReadCloser() -// bytes, err := ioutil.ReadAll(reader) +// bytes, err := io.ReadAll(reader) // err := reader.Close() // str := string(bytes) // // //Do this instead: // str, err := obj.Download(nil).AsString() // -//Since all methods on DownloadedObject are irreversible, the idiomatic way of -//using DownloadedObject is to call one of its members immediately, without -//storing the DownloadedObject instance in a variable first. +// Since all methods on DownloadedObject are irreversible, the idiomatic way of +// using DownloadedObject is to call one of its members immediately, without +// storing the DownloadedObject instance in a variable first. // // var obj *swift.Object // @@ -55,26 +54,26 @@ type DownloadedObject struct { err error } -//AsReadCloser returns an io.ReadCloser containing the contents of the -//downloaded object. +// AsReadCloser returns an io.ReadCloser containing the contents of the +// downloaded object. func (o DownloadedObject) AsReadCloser() (io.ReadCloser, error) { return o.r, o.err } -//AsByteSlice collects the contents of this downloaded object into a byte slice. +// AsByteSlice collects the contents of this downloaded object into a byte slice. func (o DownloadedObject) AsByteSlice() ([]byte, error) { if o.err != nil { return nil, o.err } - slice, err := ioutil.ReadAll(o.r) + slice, err := io.ReadAll(o.r) closeErr := o.r.Close() if err == nil { err = closeErr } - return slice, closeErr + return slice, err } -//AsString collects the contents of this downloaded object into a string. +// AsString collects the contents of this downloaded object into a string. func (o DownloadedObject) AsString() (string, error) { slice, err := o.AsByteSlice() return string(slice), err |
