-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Blob#downloadTo
is the library's efficient method for downloading blob data to an arbitrary sink. It is efficient because, unlike Storage#reader
, it downloads the blob in one request as opposed to many, and because it performs much less copying. This results in significantly higher throughput and significantly lower memory pressure.
The sequence of Storage#get
followed by Blob#downloadTo
, which is required to use this API, is prone to races. This is due to the way that the blob's generation, as it existed at Storage#get
, is unconditionally encoded into the HTTP request generated by Blob#downloadTo
. If the bucket does not use versioning, the generation may change between Storage#get
and Blob#downloadTo
, leading to a 404.
With Storage#reader
we can avoid this problem by not specifying the generation, for example using reader(String, String)
, which will read the latest generation. No such workaround is possible with Blob#downloadTo
, meaning that a usage of Blob#downloadTo
has to have a fallback that catches the 404 and retries using Storage#reader
with the generation unspecified. This is inefficient and inelegant, and should not be required.