Skip to content

Commit ea1b0cc

Browse files
committed
DOC: Add a comment explaining readinto/frombuffer idiom
1 parent 7cf14a3 commit ea1b0cc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nibabel/streamlines/trk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ def _read_header(fileobj):
556556
start_position = fileobj.tell() if hasattr(fileobj, 'tell') else None
557557

558558
with Opener(fileobj) as f:
559-
560-
# Read the header into a bytearray.
559+
# Reading directly from a file into a (mutable) bytearray enables a zero-copy
560+
# cast to a mutable numpy object with frombuffer
561561
header_buf = bytearray(header_2_dtype.itemsize)
562562
f.readinto(header_buf)
563563
header_rec = np.frombuffer(buffer=header_buf, dtype=header_2_dtype)

0 commit comments

Comments
 (0)