uproot.sink.file.FileSink
Defined in uproot.sink.file on line 25.
- class uproot.sink.file.FileSink(urlpath_or_file_like: str | IO, mode: str = 'update', **storage_options)
- Parameters:
urlpath_or_file_like (str, Path, or file-like object) – If a string or Path, a filesystem URL that specifies the file to open by fsspec. If a file-like object, it must have
read,write,seek,tell, andflushmethods.mode ("create", "recreate", or "update") – Like ROOT’s
TFileoptions."create"raisesFileExistsErrorif the path already exists (a file-like object is neither checked nor truncated),"recreate"truncates an existing file (or a file-like object that has atruncatemethod), and"update"keeps its contents. In all three, a missing path is created along with its parent directories.
An object that can write (and read) files on a local or remote filesystem. It can be initialized from a file-like object (already opened) or a filesystem URL. If initialized from a filesystem URL, fsspec is used to open the file. In this case the file is opened in the first read or write operation, unless it has to be truncated first.
from_object
- FileSink.from_object
True if constructed with a file-like object; False otherwise.
file_path
- FileSink.file_path
A path to the file, which is None if constructed with a file-like object.
tell
- FileSink.tell() int
Calls the file or file-like object’s
tellmethod.
flush
- FileSink.flush() None
Calls the file or file-like object’s
flushmethod.
closed
- FileSink.closed
True if the file has been closed; False otherwise.
close
- FileSink.close()
Closes the file (calls
closeif it has such a method) and marks the sink as closed so that closure is permanent: subsequent reads or writes raise instead of silently reopening the file.
in_path
- FileSink.in_path
write
- FileSink.write(location: int, serialization) int
- 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
seekandwritemethods.
set_file_length
- FileSink.set_file_length(length: int)
Sets the file’s length to
length, truncating with zeros if necessary.Calls
seek,tell, and possiblywrite.
read
- FileSink.read(location: int, num_bytes: int, insist: bool = True) bytes
- 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_bytescannot 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
seekandreadmethods. Theinsistparameter can be used to ensure that the output has the requested length.