Skip to content

Commit ea4e625

Browse files
committed
Clarify File/IO documentation
Update documentation to clarify the need for a File-like IO object to create GCS File/Objects with. The underlying libraries call #size on the object, which is not present on IO, but is present on File and StringIO.
1 parent 04634e6 commit ea4e625

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

google-cloud-storage/lib/google/cloud/storage/bucket.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ def file path, generation: nil, skip_lookup: nil, encryption_key: nil
561561

562562
##
563563
# Creates a new {File} object by providing a path to a local file (or
564-
# any IO or IO-ish object) to upload, along with the path at which to
565-
# store it in the bucket.
564+
# any File-like object such as StringIO) to upload, along with the path
565+
# at which to store it in the bucket.
566566
#
567567
# #### Customer-supplied encryption keys
568568
#
@@ -577,9 +577,9 @@ def file path, generation: nil, skip_lookup: nil, encryption_key: nil
577577
# and you can read or update the metadata of an encrypted file without
578578
# providing the encryption key.
579579
#
580-
# @param [String, IO] file Path of the file on the filesystem to
581-
# upload. Can be an IO object, or IO-ish object like StringIO. (If the
582-
# IO object does not have path, a `path` argument must be also be
580+
# @param [String, ::File] file Path of the file on the filesystem to
581+
# upload. Can be an File object, or File-like object such as StringIO.
582+
# (If the object does not have path, a `path` argument must be also be
583583
# provided.)
584584
# @param [String] path Path to store the file in Google Cloud Storage.
585585
# @param [String] acl A predefined set of access controls to apply to

google-cloud-storage/lib/google/cloud/storage/file.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def update
411411
end
412412

413413
##
414-
# Download the file's contents to a local file or an IO instance.
414+
# Download the file's contents to a local file or an File-like object.
415415
#
416416
# By default, the download is verified by calculating the MD5 digest.
417417
#
@@ -420,11 +420,12 @@ def update
420420
# was used with {Bucket#create_file}, the `encryption_key` option must
421421
# be provided.
422422
#
423-
# @param [String, IO] path The path on the local file system to write
424-
# the data to. The path provided must be writable. Can also be an IO
425-
# object, or IO-ish object like StringIO. If an IO object, the object
426-
# will be written to, not the filesystem. If omitted, a new StringIO
427-
# instance will be written to and returned. Optional.
423+
# @param [String, ::File] path The path on the local file system to
424+
# write the data to. The path provided must be writable. Can also be
425+
# an File object, or File-like object such as StringIO. If an file
426+
# object, the object will be written to, not the filesystem. If
427+
# omitted, a new StringIO instance will be written to and returned.
428+
# Optional.
428429
# @param [Symbol] verify The verification algorithm used to ensure the
429430
# downloaded file contents are correct. Default is `:md5`.
430431
#
@@ -446,11 +447,11 @@ def update
446447
# not performed in the Storage service. (See [Transcoding of
447448
# gzip-compressed files](https://cloud.google.com/storage/docs/transcoding))
448449
#
449-
# @return [IO] Returns an IO object representing the file data. This
450-
# will ordinarily be a `::File` object referencing the local file
451-
# system. However, if the argument to `path` is `nil`, a StringIO
452-
# instance will be returned. If the argument to `path` is an IO
453-
# object, then that object will be returned.
450+
# @return [::File, StringIO] Returns a file object representing the file
451+
# data. This will ordinarily be a `::File` object referencing the
452+
# local file system. However, if the argument to `path` is `nil`, a
453+
# StringIO instance will be returned. If the argument to `path` is an
454+
# File-like object, then that object will be returned.
454455
#
455456
# @example
456457
# require "google/cloud/storage"

0 commit comments

Comments
 (0)