docs: def write(self, b):
          """
          Write the given bytes-like object, b, to the underlying raw stream,
          and return the number of bytes written.
  
          Args:
              b (bytes-like object): Bytes to write.
  
          Returns:
              int: The number of bytes written.
          """
          if not self._writable:
              raise UnsupportedOperation('write')
  
          size = len(b)
          b_view = memoryview(b)
          size_left = size
          buffer_size = self._buffer_size
          max_buffers = self._max_buffers
  
          with self._seek_lock:
              end = self._buffer_seek
              buffer_view = memoryview(self._write_buffer)
  
              while size_left > 0:
                  # Get range to copy
                  start = end
                  end = start + size_left
  
                  if end > buffer_size:
                      # End of buffer, need flush after copy
                      end = buffer_size
                      flush = True
                  else:
                      flush = False
  
                  buffer_range = end - start
  
                  # Update not remaining data size
                  b_start = size - size_left
                  size_left -= buffer_range
  
                  # Copy data
                  buffer_view[start:end] = b_view[b_start: b_start + buffer_range]
  
                  # Flush buffer if needed
                  if flush:
                      # Update buffer seek
                      # Needed to write the good amount of data
                      self._buffer_seek = end
  
                      # Update global seek, this is the number
                      # of buffer flushed
                      self._seek += 1
  
                      # Block flush based on maximum number of
                      # buffers in flush progress
                      if max_buffers:
                          futures = self._write_futures
                          flush_wait = self._FLUSH_WAIT
                          while sum(1 for future in futures
                                    if not future.done()) >= max_buffers:
                              sleep(flush_wait)
  
                      # Flush
                      with handle_os_exceptions():
                          self._flush()
  
                      # Clear buffer
                      self._write_buffer = bytearray(buffer_size)
                      buffer_view = memoryview(self._write_buffer)
                      end = 0
  
              # Update buffer seek
              self._buffer_seek = end
              return size