Skip to content

Commit 022aef8

Browse files
authored
fix(core): download with destination as pathname (#17120)
1 parent 62d6f0e commit 022aef8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

google-apis-core/lib/google/apis/core/download.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def prepare!
3535
@state = :start
3636
@download_url = nil
3737
@offset = 0
38-
if download_dest.respond_to?(:write)
38+
if @download_dest.is_a?(Pathname)
39+
@download_io = File.open(download_dest, 'wb')
40+
@close_io_on_finish = true
41+
elsif download_dest.respond_to?(:write)
3942
@download_io = download_dest
4043
@close_io_on_finish = false
4144
elsif download_dest.is_a?(String)

google-apis-core/spec/google/apis/core/download_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,14 @@ def write(data)
135135
end
136136
end
137137
end
138+
139+
context 'with pathname destination' do
140+
let(:dest) { Pathname.new(File.join(Dir.mktmpdir, 'test-path.txt')) }
141+
let(:received) do
142+
command.execute(client)
143+
File.read(dest)
144+
end
145+
146+
include_examples 'should download'
147+
end
138148
end

0 commit comments

Comments
 (0)