Skip to content

Commit

Permalink
Refactor comments and docstrings for clarity and detail
Browse files Browse the repository at this point in the history
Enhanced comments and docstrings for better readability and detail in client.go and b64linebreaker.go. Updated descriptions, added parameter and return details, and included RFC references where applicable for improved documentation quality.
  • Loading branch information
wneessen committed Oct 6, 2024
1 parent b4197a1 commit d642606
Show file tree
Hide file tree
Showing 2 changed files with 304 additions and 97 deletions.
29 changes: 25 additions & 4 deletions b64linebreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ var newlineBytes = []byte(SingleNewLine)
// ErrNoOutWriter is the error message returned when no io.Writer is set for Base64LineBreaker.
const ErrNoOutWriter = "no io.Writer set for Base64LineBreaker"

// Base64LineBreaker is used to handle base64 encoding with the insertion of new lines after a certain
// number of characters.
// Base64LineBreaker handles base64 encoding with the insertion of new lines after a certain number
// of characters.
//
// It satisfies the io.WriteCloser interface.
// This struct is used to manage base64 encoding while ensuring that new lines are inserted after
// reaching a specific line length. It satisfies the io.WriteCloser interface.
//
// References:
// - https://datatracker.ietf.org/doc/html/rfc2045 (Base64 and line length limitations)
type Base64LineBreaker struct {
line [MaxBodyLength]byte
used int
out io.Writer
}

// Write writes data to the Base64LineBreaker, ensuring lines do not exceed MaxBodyLength.
// It handles continuation if data length exceeds the limit and writes new lines accordingly.
//
// This method writes the provided data to the Base64LineBreaker. It ensures that the written
// lines do not exceed the MaxBodyLength. If the data exceeds the limit, it handles the
// continuation by splitting the data and writing new lines as necessary.
//
// Parameters:
// - data: A byte slice containing the data to be written.
//
// Returns:
// - numBytes: The number of bytes written.
// - err: An error if one occurred during the write operation.
func (l *Base64LineBreaker) Write(data []byte) (numBytes int, err error) {
if l.out == nil {
err = errors.New(ErrNoOutWriter)
Expand Down Expand Up @@ -60,6 +74,13 @@ func (l *Base64LineBreaker) Write(data []byte) (numBytes int, err error) {
}

// Close finalizes the Base64LineBreaker, writing any remaining buffered data and appending a newline.
//
// This method ensures that any remaining data in the buffer is written to the output and appends
// a newline. It is used to finalize the Base64LineBreaker and should be called when no more data
// is expected to be written.
//
// Returns:
// - err: An error if one occurred during the final write operation.
func (l *Base64LineBreaker) Close() (err error) {
if l.used > 0 {
_, err = l.out.Write(l.line[0:l.used])
Expand Down
Loading

0 comments on commit d642606

Please sign in to comment.