Skip to content

Commit 3618219

Browse files
authored
Merge pull request #86 from jstuckey/remove_duplicate_rewind
Remove duplicate Net::SFTP::Operations::File#rewind
2 parents f5b9b4d + d6b66d5 commit 3618219

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/net/sftp/operations/file.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ def readline(sep_or_limit=$/, limit=Float::INFINITY)
127127
return line
128128
end
129129

130-
# Resets position to beginning of file
131-
def rewind
132-
@pos = 0
133-
@real_pos = 0
134-
@real_eof = false
135-
@buffer = ""
136-
end
137-
138130
# Writes the given data to the stream, incrementing the file position and
139131
# returning the number of bytes written.
140132
def write(data)
@@ -157,6 +149,7 @@ def size
157149
stat.size
158150
end
159151

152+
# Resets position to beginning of file
160153
def rewind
161154
self.pos = 0
162155
end

test/test_file.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ def test_rewind_should_reset_to_beginning_of_file
142142
assert_equal 0, @file.pos
143143
end
144144

145+
def test_rewind
146+
@sftp.expects(:write!).with("handle", 0, "hello world\n")
147+
@sftp.expects(:read!).with("handle", 12, 8192).returns("hello world\n")
148+
@sftp.expects(:read!).with("handle", 0, 8192).returns("hello world\n")
149+
@file.puts "hello world\n"
150+
assert_equal "hello", @file.read(5)
151+
@file.rewind
152+
assert_equal "hello world", @file.read(11)
153+
end
154+
145155
def test_write_should_write_data_and_increment_pos_and_return_data_length
146156
@sftp.expects(:write!).with("handle", 0, "hello world")
147157
assert_equal 11, @file.write("hello world")
@@ -202,14 +212,4 @@ def test_size_should_return_size_from_stat
202212
@sftp.expects(:fstat!).with("handle").returns(stat)
203213
assert_equal 1024, @file.size
204214
end
205-
206-
def test_rewind
207-
@sftp.expects(:write!).with("handle", 0, "hello world\n")
208-
@sftp.expects(:read!).with("handle", 12, 8192).returns("hello world\n")
209-
@sftp.expects(:read!).with("handle", 0, 8192).returns("hello world\n")
210-
@file.puts "hello world\n"
211-
assert_equal "hello", @file.read(5)
212-
@file.rewind
213-
assert_equal "hello world", @file.read(11)
214-
end
215215
end

0 commit comments

Comments
 (0)