// NewLimitedBufferReader returns a reader that reads from the given reader // but limits the amount of data returned to at most n bytes. func NewLimitedBufferReader(r io.Reader, n int) io.Reader { … } type limitedBufferReader … func (r *limitedBufferReader) Read(p []byte) (n int, err error) { … }