Skip to content

Commit ef67be4

Browse files
Add size method to file operations.
1 parent 16753a6 commit ef67be4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/net/sftp/operations/file.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def print(*items)
131131
nil
132132
end
133133

134+
# Returns the size of the file from stats
135+
def size
136+
stat.size
137+
end
138+
134139
# Writes each argument to the stream, appending a newline to any item
135140
# that does not already end in a newline. Array arguments are flattened.
136141
def puts(*items)

test/test_file.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,10 @@ def test_stat_should_return_attributes_object_for_handle
156156
@sftp.expects(:fstat!).with("handle").returns(stat)
157157
assert_equal stat, @file.stat
158158
end
159-
end
159+
160+
def test_size_should_return_size_from_stat
161+
stat = stub(size: 1024)
162+
@sftp.expects(:fstat!).with("handle").returns(stat)
163+
assert_equal 1024, @file.size
164+
end
165+
end

0 commit comments

Comments
 (0)