'Write a chunk of data to disk. All invocations of this method must
come before invoking the :func:
For this implementation, the data is written into a temporary file.
:param chunk: the chunk of data to write as a string object
:returns: the total number of bytes written to an object'

def write(self, chunk):

    while chunk:
        written = os.write(self._fd, chunk)
        self._upload_size += written
        chunk = chunk[written:]
    diff = (self._upload_size - self._last_sync)
    if (diff >= self._bytes_per_sync):
        tpool_reraise(fdatasync, self._fd)
        drop_buffer_cache(self._fd, self._last_sync, diff)
        self._last_sync = self._upload_size
    return self._upload_size
