Allow download destination to only respond to #write (#638)

According to the documentation the destination IO only needs to respond
to #write. However, the downloader breaks this by calling #flush.

We fix this by calling #flush only if the destination IO responds to
that method. We also add a test to enforce that the destination IO only
needs to respond to #write.
This commit is contained in:
Janko Marohnić authored and Daniel Azuma committed 2018-12-04 13:09:11 -08:00
1 parent d6247a7794
commit e20e6bdffd
2 files changed
+21 -8

No files matched your search

+2 -2
View File
@@ -99,7 +99,7 @@ module Google
@offset += next_chunk.bytesize
end
@download_io.flush
@download_io.flush if @download_io.respond_to?(:flush)
if @close_io_on_finish
result = nil
@@ -109,7 +109,7 @@ module Google
check_status(http_res.status.to_i, http_res.header, http_res.body)
success(result, &block)
rescue => e
@download_io.flush
@download_io.flush if @download_io.respond_to?(:flush)
error(e, rethrow: true, &block)
end
end