Ability to drain underlying chunkReader
Is your feature request related to a problem? Please describe. I've recently written a postgres proxy whose purpose is primarily to perform authentication/gasket between different transport protocols. Once the initial setup is done, I'd rather not interpret the actual postgres messages: I want my proxy to be a simple data pump, so that I don't need to worry about versioning/compatiblity/etc. I used pgproto3/pgconn3 to do this, but that library is now EOL in favour of pgx.
To achieve my goal with the old version of the library, I wrote a simple shim around the ChunkedReader that allowed me to 'drain' it once I was done the connection setup. Post-drain, I simply did an io.Copy between the two sides of the connection. Note that this is necessary because the ChunkedReader's buffer will lead to lost messages if I switch to the io.Copy without first reading them (and I can't know up front how many there are in the buffer).
I can no longer do this, because the underling ChunkedReader is no longer exposed/exported.
Describe the solution you'd like I would like the ability to take back ownership of either side of the data stream without losing any data that was buffered during the connection setup. The simplest solution for me would be to export the ChunkedReader interface, and then provide a variant of New(Back|Front)end that takes the ChunkedReader as input, like it used to.
Alternatively, an exported method on the two structs that gives me more control here would work, though given how simple their interface is right now that seems like overkill.
Another alternative could be to export an interface which the provided io.Reader implements that could be used to optionally turn on this behaviour somehow.
Describe alternatives you've considered I considered just writing a loop that proxies by reading messages from one side and then sending them out the other, but that seems quite a bit more fragile than just copy the raw bytes uninterpreted, and propagating the connection state.
I could try flushing the buffer by forcing the io.Reader to return EOF, and then reading messages until the Receive function fails, but if the buffer has only received part of a message, this will still lead to lost data, because I cannot read those bytes.
I think https://pkg.go.dev/github.com/jackc/pgx/v5/pgconn#PgConn.Hijack is what you want.