Skip to content

Commit

Permalink
Merge pull request #3408 from jiumao2/main
Browse files Browse the repository at this point in the history
Update the method of creating an empty file with right size when saving binary files
  • Loading branch information
alejoe91 authored Sep 16, 2024
2 parents 8a1870c + af6c618 commit 55c7de1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/spikeinterface/core/recording_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ def write_binary_recording(
data_size_bytes = dtype_size_bytes * num_frames * num_channels
file_size_bytes = data_size_bytes + byte_offset

file = open(file_path, "wb+")
file.truncate(file_size_bytes)
file.close()
# Create an empty file with file_size_bytes
with open(file_path, "wb+") as file:
# The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408)
file.seek(file_size_bytes - 1)
file.write(b"\0")

assert Path(file_path).is_file()

# use executor (loop or workers)
Expand Down

0 comments on commit 55c7de1

Please sign in to comment.