From 56efac769d260e17cd00a0ffc5fe0ed556879d5b Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Wed, 15 Oct 2025 16:32:21 +0100 Subject: [PATCH] fix: only check for bin file size if it exists --- neo/rawio/spikeglxrawio.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/neo/rawio/spikeglxrawio.py b/neo/rawio/spikeglxrawio.py index 5a25e5d29..ae9a45e9b 100644 --- a/neo/rawio/spikeglxrawio.py +++ b/neo/rawio/spikeglxrawio.py @@ -695,9 +695,12 @@ def extract_stream_info(meta_file, meta): # Calculate sample_length from actual file size instead of metadata to handle stub/modified files # The metadata fileSizeBytes may not match the actual .bin file (e.g., in test stub files) # Original calculation (only correct for unmodified files): - # info["sample_length"] = int(meta["fileSizeBytes"]) // 2 // num_chan - actual_file_size = Path(meta_file).with_suffix(".bin").stat().st_size - info["sample_length"] = actual_file_size // 2 // num_chan # 2 bytes per int16 sample + bin_file = Path(meta_file).with_suffix(".bin") + if bin_file.exists(): + file_size = bin_file.stat().st_size + else: + file_size = int(meta["fileSizeBytes"]) + info["sample_length"] = file_size // 2 // num_chan # 2 bytes per int16 sample info["gate_num"] = gate_num info["trigger_num"] = trigger_num info["device"] = device