Skip to content

Commit 2a0cf02

Browse files
committed
open files in binary mode to appease Windows
1 parent 8f1eb74 commit 2a0cf02

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

CHANGELOG.rdoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
=== *unreleased*
2+
3+
* Open files in binary mode to appease Windows [Jamis Buck]
4+
5+
16
=== 2.0.0 / 1 May 2008
27

38
* Make Net::SSH::Connection::Session#sftp accept an argument determining whether or not to block while the SFTP subsystem initializes (defaults to true) [Jamis Buck]

lib/net/sftp/operations/download.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def on_open(response)
307307
raise "open #{entry.remote}: #{response}" unless response.ok?
308308

309309
entry.handle = response[:handle]
310-
entry.sink = entry.local.respond_to?(:write) ? entry.local : ::File.open(entry.local, "w")
310+
entry.sink = entry.local.respond_to?(:write) ? entry.local : ::File.open(entry.local, "wb")
311311
entry.offset = 0
312312

313313
download_next_chunk(entry)

lib/net/sftp/operations/upload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def open_file(local, remote)
276276
file = local
277277
name = options[:name] || "<memory>"
278278
else
279-
file = ::File.open(local)
279+
file = ::File.open(local, "rb")
280280
name = local
281281
end
282282

test/test_download.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_download_file_should_transfer_remote_to_local
1313
expect_file_transfer(remote, text)
1414

1515
file = StringIO.new
16-
File.stubs(:open).with(local, "w").returns(file)
16+
File.stubs(:open).with(local, "wb").returns(file)
1717

1818
assert_scripted_command { sftp.download(remote, local) }
1919
assert_equal text, file.string
@@ -143,7 +143,7 @@ def prepare_large_file_download(local, remote, text)
143143
end
144144

145145
file = StringIO.new
146-
File.stubs(:open).with(local, "w").returns(file)
146+
File.stubs(:open).with(local, "wb").returns(file)
147147

148148
return file
149149
end
@@ -244,8 +244,8 @@ def prepare_directory_tree_download(local, remote)
244244

245245
file1 = StringIO.new
246246
file2 = StringIO.new
247-
File.expects(:open).with(File.join(local, "file1"), "w").returns(file1)
248-
File.expects(:open).with(File.join(local, "subdir1", "file2"), "w").returns(file2)
247+
File.expects(:open).with(File.join(local, "file1"), "wb").returns(file1)
248+
File.expects(:open).with(File.join(local, "subdir1", "file2"), "wb").returns(file2)
249249

250250
[file1, file2]
251251
end

test/test_upload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def expect_file(path, data)
196196
File.stubs(:exists?).with(path).returns(true)
197197
file = StringIO.new(data)
198198
file.stubs(:stat).returns(stub("stat", :size => data.length))
199-
File.stubs(:open).with(path).returns(file)
199+
File.stubs(:open).with(path, "rb").returns(file)
200200
end
201201

202202
def expect_directory(path, entries)

0 commit comments

Comments
 (0)