Skip to content

Commit

Permalink
Skip empty files in G3Reader
Browse files Browse the repository at this point in the history
Avoid throwing an IO error when an empty G3 file is included in the input
filenames by silently moving on to the next file in the list until reaching a
non-empty file or the end of the list.

Fixes #134.
  • Loading branch information
arahlin committed Jan 24, 2024
1 parent 7052169 commit 27a73a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/G3Reader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void G3Reader::Process(G3FramePtr frame, std::deque<G3FramePtr> &out)
if (Py_IsInitialized())
_save = PyEval_SaveThread();

if (stream_.peek() == EOF) {
while (stream_.peek() == EOF) {
if (filename_.size() > 0) {
StartFile(filename_.front());
filename_.pop_front();
Expand Down
9 changes: 9 additions & 0 deletions core/tests/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ def checkinfo(fr):
n += 1
pipe.Add(checkinfo)
pipe.Run()
assert n == 10, 'Wrong number of frames read (%d should be %d)' % (n, 10)

# Skip empty files
wr = core.G3Writer("empty.g3")
del wr
n = 0
pipe = core.G3Pipeline()
pipe.Add(core.G3Reader, filename=["empty.g3", "test.g3", "empty.g3"], track_filename=True)
pipe.Add(checkinfo)
pipe.Run()
assert n == 10, 'Wrong number of frames read (%d should be %d)' % (n, 10)

# Indexing
Expand Down

0 comments on commit 27a73a7

Please sign in to comment.