Skip to content

Commit

Permalink
Merge branch 'hotfix/seek'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Jan 22, 2019
2 parents 2a5f172 + be373cc commit ce440c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ end


function seekNextRecord(io::IO) :: Nothing
seekstart(io)

pos = position(io)
initial = pos == 0 ? -1 : pos # Note: Allows for the fist line of headerless bedGraph file to be read.
line = ""

while !eof(io) && !isLikeRecord(line)
while !eof(io) && (!isLikeRecord(line) || pos == initial)
pos = position(io)
line = readline(io)
end
Expand Down Expand Up @@ -57,6 +57,7 @@ function readRecord(io::IO) :: Union{Nothing, Record}
end

function readRecords(io::IO) :: Vector{Record}
seekstart(io)
seekNextRecord(io)

records = Vector{Record}()
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ end

# Check things for headerless Bag.files.
open(Bag.file_headerless, "r") do io

# Check that the first record of a headerless bedGraph file can be sought.
Bedgraph.seekNextRecord(io)
@test position(io) == 0
@test readline(io) == Bag.line1
@test readline(io) == Bag.line1 # IO position is at the start of line 2.

# Check behaviour of consecutive calls to Bedgraph.seekNextRecord(io).
Bedgraph.seekNextRecord(io) # Skip to start of line 3.
Bedgraph.seekNextRecord(io) # Skip to start of line 4.
@test readline(io) == Bag.line4

end


Expand Down

0 comments on commit ce440c9

Please sign in to comment.