newChunkReader creates and returns a new chunkReader for r with default configuration. If minBufSize is <= 0 it uses a default value.
(r io.Reader, minBufSize int)
| 23 | // newChunkReader creates and returns a new chunkReader for r with default configuration. If minBufSize is <= 0 it uses |
| 24 | // a default value. |
| 25 | func newChunkReader(r io.Reader, minBufSize int) *chunkReader { |
| 26 | if minBufSize <= 0 { |
| 27 | // By historical reasons Postgres currently has 8KB send buffer inside, |
| 28 | // so here we want to have at least the same size buffer. |
| 29 | // @see https://github.com/postgres/postgres/blob/249d64999615802752940e017ee5166e726bc7cd/src/backend/libpq/pqcomm.c#L134 |
| 30 | // @see https://www.postgresql.org/message-id/0cdc5485-cb3c-5e16-4a46-e3b2f7a41322%40ya.ru |
| 31 | // |
| 32 | // In addition, testing has found no benefit of any larger buffer. |
| 33 | minBufSize = 8192 |
| 34 | } |
| 35 | |
| 36 | return &chunkReader{ |
| 37 | r: r, |
| 38 | minBufSize: minBufSize, |
| 39 | buf: iobufpool.Get(minBufSize), |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Next returns buf filled with the next n bytes. buf is only valid until next call of Next. If an error occurs, buf |
| 44 | // will be nil. |