def write_file(self, sfile, nbytes=0, offset=0, flush=False):
        """
        Write a file to the channel.

        The file will not be written immediately, but will be buffered
        internally until it can be sent without blocking the process.

        Calling :meth:`write_file()` on a closed or disconnected channel
        will raise a :exc:`RuntimeError`.

        ==========  ====================================================
        Arguments   Description
        ==========  ====================================================
        sfile       A file object to write to the channel.
        nbytes      *Optional.* The number of bytes of the file to
                    write. If 0, all bytes will be written.
        offset      *Optional.* The number of bytes to offset writing
                    by.
        flush       *Optional.* If True, flush the internal write
                    buffer. See :meth:`~pants.stream.Stream.flush` for
                    details.
        ==========  ====================================================
        """
        if self._closed or self._closing:
            raise RuntimeError("write_file() called on closed %r." % self)

        if not self.connected:
            raise RuntimeError("write_file() called on disconnected %r." % self)

        self._send_buffer.append((Stream.SEND_FILE, (sfile, offset, nbytes)))

        if flush:
            self._process_send_buffer()
        else:
            self._start_waiting_for_write_event()
dataset/ETHPy150Open ecdavis/pants/pants/stream.py/Stream.write_file/original