Skip to content

Commit

Permalink
Fix detection of truncated data records for BDF files (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Nov 3, 2022
1 parent e7c6249 commit 92a6db8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EDF"
uuid = "ccffbfc1-f56e-50fb-a33b-53d1781b2825"
authors = ["Beacon Biosignals, Inc."]
version = "0.7.3"
version = "0.7.4"

[deps]
BitIntegers = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1"
Expand Down
2 changes: 1 addition & 1 deletion src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function File(io::IO)
return signal.samples_per_record
end
end
readable_records = div(div(bytes_left, 2), total_expected_samples)
readable_records = div(div(bytes_left, sizeof(T)), total_expected_samples)
if file_header.record_count > readable_records
@warn("Number of data records in file header does not match file size. " *
"Skipping $(file_header.record_count - readable_records) truncated " *
Expand Down
9 changes: 5 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ const DATADIR = joinpath(@__DIR__, "data")
end

# Truncated files
mktempdir() do dir
dir = mktempdir(; cleanup=true)
for full_file in ["test.edf", "evt.bdf"]
# note that this tests a truncated final record, not an incorrect number of records
full_file = joinpath(DATADIR, "test.edf")
truncated_file = joinpath(dir, "test_truncated.edf")
full_edf_bytes = read(full_file)
truncated_file = joinpath(dir, "test_truncated" * last(splitext(full_file)))
full_edf_bytes = read(joinpath(DATADIR, full_file))
write(truncated_file, full_edf_bytes[1:(end - 1)])
@test_logs((:warn, "Number of data records in file header does not match " *
"file size. Skipping 1 truncated data record(s)."),
EDF.read(truncated_file))
edf = EDF.read(joinpath(DATADIR, full_file))
truncated_edf = EDF.read(truncated_file)
for field in fieldnames(EDF.FileHeader)
a = getfield(edf.header, field)
Expand Down

2 comments on commit 92a6db8

@ararslan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71592

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.4 -m "<description of version>" 92a6db8d8d9272f20b3e434346acdb1139c50d97
git push origin v0.7.4

Please sign in to comment.