Skip to content

Commit 3e65c3f

Browse files
committed
fix file chunk arg validation
1 parent f0b29d3 commit 3e65c3f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/kanrisuru/core/stream.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def tail(path, opts = {})
3535
end
3636

3737
def read_file_chunk(path, start_line, end_line)
38-
if start_line.instance_of?(Integer) || end_line.instance_of?(Integer) ||
39-
start_line > end_line || start_line.negative?
38+
if !start_line.instance_of?(Integer) || !end_line.instance_of?(Integer) ||
39+
start_line > end_line || start_line.negative? || end_line.negative?
4040
raise ArgumentError, 'Invalid start or end'
4141
end
4242

spec/functional/core/stream_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@
7474
expect(result.data).to eq(['a', 'file!'])
7575
end
7676

77+
it 'reads a chunk of text from a file' do
78+
file = host.file("#{spec_dir}/test-file-chunk.txt")
79+
file.touch
80+
file.append do |f|
81+
f << 'This'
82+
f << 'is'
83+
f << 'is'
84+
f << 'a'
85+
f << 'file'
86+
f << 'forever...'
87+
end
88+
89+
result = host.read_file_chunk("#{spec_dir}/test-file-chunk.txt", 2, 4)
90+
expect(result).to be_success
91+
expect(result.data.length).to eq(3)
92+
expect(result.data).to eq(['is', 'is', 'a'])
93+
end
94+
7795
it 'cats a file' do
7896
result = host.cat('/etc/group')
7997
expect(result.success?).to eq(true)

0 commit comments

Comments
 (0)