From 0f0c72e7720b63f67941507fa5926110bfdf31f2 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Fri, 13 Sep 2024 21:20:32 +0800 Subject: [PATCH 1/6] Update recording_tools.py Update the method to create an empty file with the right size --- src/spikeinterface/core/recording_tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 5137eda545..2e93b3671b 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -131,8 +131,10 @@ def write_binary_recording( data_size_bytes = dtype_size_bytes * num_frames * num_channels file_size_bytes = data_size_bytes + byte_offset + # create a file with file_size_bytes file = open(file_path, "wb+") - file.truncate(file_size_bytes) + file.seek(file_size_bytes - 1) + file.write(b'\0') file.close() assert Path(file_path).is_file() From 2cb34c3fd6d9f2296d5c9acdc1b00d608e8531c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:40:59 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/recording_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 2e93b3671b..c18e461f90 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -134,7 +134,7 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") file.seek(file_size_bytes - 1) - file.write(b'\0') + file.write(b"\0") file.close() assert Path(file_path).is_file() From 3f9a9011a958252547acc4589dca88d727a49b6a Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 13 Sep 2024 18:00:33 -0600 Subject: [PATCH 3/6] Update src/spikeinterface/core/recording_tools.py Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/recording_tools.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index c18e461f90..30cd54473c 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -133,7 +133,11 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") - file.seek(file_size_bytes - 1) + if platform.system() == 'Windows': + file.seek(file_size_bytes - 1) + file.write(b"\0") + else: + file.truncate(file_size_bytes) file.write(b"\0") file.close() assert Path(file_path).is_file() From d460c1ed312f5399b11100613483c3b364ef7213 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Sep 2024 00:00:54 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/recording_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 30cd54473c..f649e60b28 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -133,7 +133,7 @@ def write_binary_recording( # create a file with file_size_bytes file = open(file_path, "wb+") - if platform.system() == 'Windows': + if platform.system() == "Windows": file.seek(file_size_bytes - 1) file.write(b"\0") else: From 559cbaade8faaf9a0056da84069ddc9cb96faae3 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Mon, 16 Sep 2024 00:09:51 +0800 Subject: [PATCH 5/6] Update recording_tools.py --- src/spikeinterface/core/recording_tools.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index f649e60b28..8f42774dec 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -131,14 +131,13 @@ def write_binary_recording( data_size_bytes = dtype_size_bytes * num_frames * num_channels file_size_bytes = data_size_bytes + byte_offset - # create a file with file_size_bytes + # Create an empty file with file_size_bytes file = open(file_path, "wb+") - if platform.system() == "Windows": - file.seek(file_size_bytes - 1) - file.write(b"\0") - else: - file.truncate(file_size_bytes) + + # The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408) + file.seek(file_size_bytes - 1) file.write(b"\0") + file.close() assert Path(file_path).is_file() From af6c61807f75e98420eb2a849771fb29d57dd1f1 Mon Sep 17 00:00:00 2001 From: Yue Huang <806628409@qq.com> Date: Mon, 16 Sep 2024 00:18:20 +0800 Subject: [PATCH 6/6] Update recording_tools.py --- src/spikeinterface/core/recording_tools.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 8f42774dec..77d427bc88 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -132,13 +132,11 @@ def write_binary_recording( file_size_bytes = data_size_bytes + byte_offset # Create an empty file with file_size_bytes - file = open(file_path, "wb+") + 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") - # The previous implementation `file.truncate(file_size_bytes)` was slow on Windows (#3408) - file.seek(file_size_bytes - 1) - file.write(b"\0") - - file.close() assert Path(file_path).is_file() # use executor (loop or workers)