reader.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package storage
  15. import (
  16. "io"
  17. )
  18. // Reader reads a Cloud Storage object.
  19. type Reader struct {
  20. body io.ReadCloser
  21. size int64
  22. contentType string
  23. }
  24. func (r *Reader) Close() error {
  25. return r.body.Close()
  26. }
  27. func (r *Reader) Read(p []byte) (int, error) {
  28. return r.body.Read(p)
  29. }
  30. // Size returns the size of the object in bytes.
  31. // The returned value is always the same and is not affected by
  32. // calls to Read or Close.
  33. func (r *Reader) Size() int64 {
  34. return r.size
  35. }
  36. // ContentType returns the content type of the object.
  37. func (r *Reader) ContentType() string {
  38. return r.contentType
  39. }