fileutils

Utilities for reading and writing to binary file formats

read_zt_byte_strings(fobj[, n_strings, bufsize])

Read zero-terminated byte strings from a file object fobj

read_zt_byte_strings

nibabel.fileutils.read_zt_byte_strings(fobj, n_strings=1, bufsize=1024)

Read zero-terminated byte strings from a file object fobj

Returns byte strings with terminal zero stripped.

Found strings can be of any length.

The file position of fobj on exit will be at the byte after the terminal 0 of the final read byte string.

Parameters:
ffileobj

File object to use. Should implement read, returning byte objects, and seek(n, 1) to seek from current file position.

n_stringsint, optional

Number of byte strings to return

bufsize: int, optional

Define chunk size to load from file while searching for zero terminals. We load this many bytes at a time from the file, but the returned strings can be longer than bufsize.

Returns:
byte_stringslist

List of byte strings, where strings do not include the terminal 0