code: func (u *Uploader) Write(p []byte) (n int, err error) {
  	if len(p) == 0 {
  		return 0, nil
  	}
  
  	bufStart := u.Offset
  	bufEnd := u.Offset + int64(len(p))
  	if bufEnd > u.FileSize {
  		return 0, fmt.Errorf("attempting to write past the declared file size (%d > %d)", bufEnd, u.FileSize)
  	}
  
  	for u.Offset != bufEnd && err == nil {
  		resuming := false
  		err = withRetry(u.Context, func() error {
  			// When resuming, we upload 0 bytes chunk to grab the last known offset.
  			// Otherwise, just upload the next chunk of data.
  			var chunk []byte
  			if !resuming {
  				chunk = p[int(u.Offset-bufStart):]
  			}
  			resumeOffset, err := u.uploadChunk(chunk)
  
  			// On transient errors, try to resume right away once.
  			if apiErr, _ := err.(*googleapi.Error); apiErr != nil && apiErr.Code >= 500 {
  				logging.WithError(err).Warningf(u.Context, "Transient error, querying for last uploaded offset")
  				resuming = true
  				resumeOffset, err = u.uploadChunk(nil)
  			}
  
  			switch {
  			case err != nil:
  				// Either a fatal error during the upload or a transient or fatal error
  				// trying to resume. Let 'withRetry' handle it by retrying or failing.
  				return err
  			case resumeOffset < bufStart || resumeOffset > bufEnd:
  				// Resuming requires data we don't have? Escalate to the caller.
  				return &RestartUploadError{Offset: resumeOffset}
  			default:
  				// Resume the upload from the last acknowledged offset.
  				u.Offset = resumeOffset
  				resuming = false
  				return nil
  			}
  		})
  	}
  
  	return int(u.Offset - bufStart), err
  }
docs: // Write is part of io.Writer interface.