Skip to content

Commit

Permalink
Write chunked data to multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob720 committed Jan 7, 2025
1 parent 6949cb5 commit af80b13
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/aa_remove_data/pb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, filepath: PathLike | None = None, chunk_size=10000000):
self.read_done = False
self._chunk_size = chunk_size
self._start_line = 0
self._write_started = False
self._write_started = []

Check warning on line 30 in src/aa_remove_data/pb_utils.py

View check run for this annotation

Codecov / codecov/patch

src/aa_remove_data/pb_utils.py#L26-L30

Added lines #L26 - L30 were not covered by tests
if filepath:
self.read_pb(filepath)

Expand Down Expand Up @@ -215,13 +215,15 @@ def write_pb(self, filepath: PathLike):
self._replace_newline_chars(sample.SerializeToString()) + b"\n"
for sample in self.samples
]
if self._write_started is False: # Write header, start new file
if (

Check warning on line 218 in src/aa_remove_data/pb_utils.py

View check run for this annotation

Codecov / codecov/patch

src/aa_remove_data/pb_utils.py#L218

Added line #L218 was not covered by tests
filepath not in self._write_started or self.chunked is False
): # Write header, start new file
header_b = (

Check warning on line 221 in src/aa_remove_data/pb_utils.py

View check run for this annotation

Codecov / codecov/patch

src/aa_remove_data/pb_utils.py#L221

Added line #L221 was not covered by tests
self._replace_newline_chars(self.header.SerializeToString()) + b"\n"
)
with open(filepath, "wb") as f:
f.writelines([header_b] + samples_b)
self._write_started = True
self._write_started.append(filepath)

Check warning on line 226 in src/aa_remove_data/pb_utils.py

View check run for this annotation

Codecov / codecov/patch

src/aa_remove_data/pb_utils.py#L224-L226

Added lines #L224 - L226 were not covered by tests
else: # Add to existing file
with open(filepath, "ab") as f:
f.writelines(samples_b)

Check warning on line 229 in src/aa_remove_data/pb_utils.py

View check run for this annotation

Codecov / codecov/patch

src/aa_remove_data/pb_utils.py#L228-L229

Added lines #L228 - L229 were not covered by tests
Expand Down

0 comments on commit af80b13

Please sign in to comment.