aboutsummaryrefslogtreecommitdiff
path: root/download.go
diff options
context:
space:
mode:
Diffstat (limited to 'download.go')
-rw-r--r--download.go27
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