uproot.sink.file.FileSink

Defined in uproot.sink.file on line 23.

class uproot.sink.file.FileSink(urlpath_or_file_like: str | IO, **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, and flush methods.

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.

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 tell method.

flush

FileSink.flush() None

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: 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 seek and write methods.

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 possibly write.

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_bytes cannot be read from the file. Otherwise, this function may return data with fewer than num_bytes.

Returns a bytes object of data from the file by calling the file-like object’s seek and read methods. The insist parameter can be used to ensure that the output has the requested length.