# uproot.sink.file.FileSink

Defined in [uproot.sink.file](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/sink/file.py) on [line 25](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/sink/file.py#L25).

### *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`, and `flush` methods.
  * **mode** ( *"create"* *,*  *"recreate"* *, or*  *"update"*) – Like ROOT’s `TFile` options.
    `"create"` raises `FileExistsError` if 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 a
    `truncate` method), 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.

<a id="uproot-sink-file-filesink-from-object"></a>

## from_object

#### FileSink.from_object

True if constructed with a file-like object; False otherwise.

<a id="uproot-sink-file-filesink-file-path"></a>

## file_path

#### FileSink.file_path

A path to the file, which is None if constructed with a file-like object.

<a id="uproot-sink-file-filesink-tell"></a>

## tell

#### FileSink.tell() → int

Calls the file or file-like object’s `tell` method.

<a id="uproot-sink-file-filesink-flush"></a>

## flush

#### FileSink.flush() → None

Calls the file or file-like object’s `flush` method.

<a id="uproot-sink-file-filesink-closed"></a>

## closed

#### FileSink.closed

True if the file has been closed; False otherwise.

<a id="uproot-sink-file-filesink-close"></a>

## close

#### FileSink.close()

Closes the file (calls `close` if 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.

<a id="uproot-sink-file-filesink-in-path"></a>

## in_path

#### FileSink.in_path

<a id="uproot-sink-file-filesink-write"></a>

## 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.

<a id="uproot-sink-file-filesink-set-file-length"></a>

## 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`.

<a id="uproot-sink-file-filesink-read"></a>

## 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.
