uproot.sink.file.FileSink
Defined in uproot.sink.file on line 17.
- class uproot.sink.file.FileSink(file_path)
- Parameters:
file_path (str) – The filesystem path of the file to open.
An object that can write (and read) files on a local filesystem, which either opens a new file from a
file_path
in"r+b"
mode or wraps a file-like object with the from_object constructor.With the
file_path
-based constructor, the file is opened upon first read or write.
from_object
- classmethod FileSink.from_object(obj)
- Parameters:
obj (file-like object) – An object with
read
,write
,seek
,tell
, andflush
methods.
Creates a uproot.sink.file.FileSink from a file-like object, such as
io.BytesIO
. The object must be readable, writable, and seekable with"r+b"
mode semantics.
file_path
- FileSink.file_path
A path to the file, which is None if constructed with a file-like object.
tell
- FileSink.tell()
Calls the file or file-like object’s
tell
method.
flush
- FileSink.flush()
Calls the file or file-like object’s
flush
method.
closed
- FileSink.closed
True if the file is closed; False otherwise.
close
- FileSink.close()
Closes the file (calls
close
if it has such a method) and sets it to None so that closure is permanent.
in_path
- FileSink.in_path
write
- FileSink.write(location, serialization)
- Parameters:
location (int) – Position in the file to write.
serialization (bytes or NumPy array) – Data to write to the file.
Writes data to the file at a specific location, calling the file-like object’s
seek
andwrite
methods.
set_file_length
- FileSink.set_file_length(length)
Sets the file’s length to
length
, truncating with zeros if necessary.Calls
seek
,tell
, and possiblywrite
.
read
- FileSink.read(location, num_bytes, insist=True)
- Parameters:
location (int) – Position in the file to read.
num_bytes (int) – Number of bytes to read from the file.
insist (bool) – If True, raise an OSError if
num_bytes
cannot be read from the file. Otherwise, this function may return data with fewer thannum_bytes
.
Returns a bytes object of data from the file by calling the file-like object’s
seek
andread
methods. Theinsist
parameter can be used to ensure that the output has the requested length.