<commit_before>package disgo

import (
	"encoding/base64"
	"fmt"
	"io"
	"io/ioutil"
)

type modifyCurrentUser struct {
	Username string `json:"username,omitempty"`
	Avatar   string `json:"avatar,omitempty"`
}

func (s *Session) SetUsername(username string) (*User, error) {
	return s.modifyCurrentUser(modifyCurrentUser{Username: username})
}

func (s *Session) SetAvatar(imageMimeType string, reader io.Reader) (*User, error) {
	bytes, _ := ioutil.ReadAll(reader)
	encoded := base64.StdEncoding.EncodeToString(bytes)
	return s.modifyCurrentUser(modifyCurrentUser{Avatar: fmt.Sprintf("data:%s;base64,%s", imageMimeType, encoded)})
}

func (s *Session) modifyCurrentUser(modification modifyCurrentUser) (*User, error) {
	user := &User{}
	err := s.doHttpPatch(EndPointOwnUser(), &modification, user)
	if err != nil {
		return nil, err
	}
	user = objects.registerUser(user)
	if user.session == nil {
		user.session = s
	}
	return user, nil
}<commit_msg>Added error returning of ioutil.ReadAll in SetAvatar()<commit_after>package disgo

import (
	"encoding/base64"
	"fmt"
	"io"
	"io/ioutil"
)

type modifyCurrentUser struct {
	Username string `json:"username,omitempty"`
	Avatar   string `json:"avatar,omitempty"`
}

func (s *Session) SetUsername(username string) (*User, error) {
	return s.modifyCurrentUser(modifyCurrentUser{Username: username})
}

func (s *Session) SetAvatar(imageMimeType string, reader io.Reader) (*User, error) {
	bytes, err := ioutil.ReadAll(reader)

	if err != nil {
		return nil, err
	}

	encoded := base64.StdEncoding.EncodeToString(bytes)
	return s.modifyCurrentUser(modifyCurrentUser{Avatar: fmt.Sprintf("data:%s;base64,%s", imageMimeType, encoded)})
}

func (s *Session) modifyCurrentUser(modification modifyCurrentUser) (*User, error) {
	user := &User{}
	err := s.doHttpPatch(EndPointOwnUser(), &modification, user)
	if err != nil {
		return nil, err
	}
	user = objects.registerUser(user)
	if user.session == nil {
		user.session = s
	}
	return user, nil
}
{'fraction_non_alphanumeric': 0.13716591023701463, 'fraction_numerical': 0.006051437216338881, 'mean_word_length': 5.68013468013468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '163700', 'n_tokens_mistral': 698, 'n_tokens_neox': 679, 'n_words': 159}