s3-orchestrator

ioutilx

import "github.com/afreidah/s3-orchestrator/internal/util/ioutilx"

Package ioutilx provides small composition helpers around io.Reader and io.ReadCloser. Helpers preserve close ordering and ensure cancel callbacks fire exactly once.

Index

func ReadCloser

func ReadCloser(r io.Reader, c io.Closer) io.ReadCloser

ReadCloser returns an io.ReadCloser that reads from r and delegates Close to c. Use when a transformation wraps a reader (decryption, metric counting, tee) but the original closer still has to run so the underlying resource (HTTP body, file, etc.) is released.

func WithCancel

func WithCancel(rc io.ReadCloser, cancel func()) io.ReadCloser

WithCancel wraps rc so Close calls both rc.Close and cancel. cancel is guarded by sync.Once, so repeated Close calls only invoke it once. Use to release per-call timeout contexts when the consumer finishes reading the body, rather than waiting for the deadline.

Generated by gomarkdoc