You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: sink.go
    path of file: ./repos/td/telegram/downloader
    
    the code of the file until where you have to start completion: package downloader

import (
	"context"
	"io"

	"github.com/go-faster/errors"
)

func writeAtLoop(w io.WriterAt, toWrite <-chan block) func(context.Context) error {
	return func(ctx context.Context) error {
		for {
			select {
			case <-ctx.Done():
				return ctx.Err()
			case part, ok := <-toWrite:
				if !ok {
					return nil
				}

				_, err := w.Wri
    
func writeLoop(w io.Writer, toWrite <-chan block) func(context.Context) error {
	return func(ctx context.Context) error {
		for {
			select {
			case <-ctx.Done():
				return ctx.Err()
			case part, ok := <-toWrite:
				if !ok {
					return nil
				}

				_, err := w.Write(part.data)
				if err != nil {
					return errors.Wrap(err, "write output")
				}
			}
		}
	}
}