summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgx/v5/large_objects.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/jackc/pgx/v5/large_objects.go')
-rw-r--r--vendor/github.com/jackc/pgx/v5/large_objects.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/vendor/github.com/jackc/pgx/v5/large_objects.go b/vendor/github.com/jackc/pgx/v5/large_objects.go
index a3028b638..9d21afdce 100644
--- a/vendor/github.com/jackc/pgx/v5/large_objects.go
+++ b/vendor/github.com/jackc/pgx/v5/large_objects.go
@@ -4,6 +4,8 @@ import (
"context"
"errors"
"io"
+
+ "github.com/jackc/pgx/v5/pgtype"
)
// The PostgreSQL wire protocol has a limit of 1 GB - 1 per message. See definition of
@@ -115,9 +117,10 @@ func (o *LargeObject) Read(p []byte) (int, error) {
expected = maxLargeObjectMessageLength
}
- var res []byte
+ res := pgtype.PreallocBytes(p[nTotal:])
err := o.tx.QueryRow(o.ctx, "select loread($1, $2)", o.fd, expected).Scan(&res)
- copy(p[nTotal:], res)
+ // We compute expected so that it always fits into p, so it should never happen
+ // that PreallocBytes's ScanBytes had to allocate a new slice.
nTotal += len(res)
if err != nil {
return nTotal, err