summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-11-27 13:16:26 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-27 13:16:26 +0000
commit1fa206c230a4077aa3f998d2f8c77aeda3280dd2 (patch)
tree31b1d2600c691ba2373934dcd555fbc2cf27f7cc /vendor/codeberg.org
parent[chore]: Bump github.com/gin-contrib/cors from 1.4.0 to 1.5.0 (#2388) (diff)
downloadgotosocial-1fa206c230a4077aa3f998d2f8c77aeda3280dd2.tar.xz
[chore]: Bump codeberg.org/gruf/go-byteutil from 1.1.2 to 1.2.0 (#2389)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org')
-rw-r--r--vendor/codeberg.org/gruf/go-byteutil/LICENSE2
-rw-r--r--vendor/codeberg.org/gruf/go-byteutil/buffer.go42
2 files changed, 42 insertions, 2 deletions
diff --git a/vendor/codeberg.org/gruf/go-byteutil/LICENSE b/vendor/codeberg.org/gruf/go-byteutil/LICENSE
index e4163ae35..d6f08d0ab 100644
--- a/vendor/codeberg.org/gruf/go-byteutil/LICENSE
+++ b/vendor/codeberg.org/gruf/go-byteutil/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2022 gruf
+Copyright (c) gruf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
diff --git a/vendor/codeberg.org/gruf/go-byteutil/buffer.go b/vendor/codeberg.org/gruf/go-byteutil/buffer.go
index 9e15c8ade..8259429d6 100644
--- a/vendor/codeberg.org/gruf/go-byteutil/buffer.go
+++ b/vendor/codeberg.org/gruf/go-byteutil/buffer.go
@@ -7,7 +7,8 @@ import (
)
var (
- // ensure we conform to interfaces.
+ // ensure we conform
+ // to interfaces.
_ interface {
io.Writer
io.ByteWriter
@@ -15,6 +16,8 @@ var (
io.StringWriter
io.WriterAt
WriteStringAt(string, int64) (int, error)
+ io.ReaderFrom
+ io.WriterTo
} = (*Buffer)(nil)
// ErrBeyondBufferLen is returned if .WriteAt() is attempted beyond buffer length.
@@ -81,6 +84,43 @@ func (buf *Buffer) WriteStringAt(s string, start int64) (int, error) {
return copy(buf.B[start:], s), nil
}
+// ReadFrom will read bytes from reader into buffer, fulfilling io.ReaderFrom.
+func (buf *Buffer) ReadFrom(r io.Reader) (int64, error) {
+ var nn int64
+
+ // Ensure there's cap
+ // for a first read.
+ buf.Guarantee(512)
+
+ for {
+ // Read into next chunk of buffer.
+ n, err := r.Read(buf.B[len(buf.B):cap(buf.B)])
+
+ // Reslice buf + update count.
+ buf.B = buf.B[:len(buf.B)+n]
+ nn += int64(n)
+
+ if err != nil {
+ if err == io.EOF {
+ // mask EOF.
+ err = nil
+ }
+ return nn, err
+ }
+
+ if len(buf.B) == cap(buf.B) {
+ // Add capacity (let append pick).
+ buf.B = append(buf.B, 0)[:len(buf.B)]
+ }
+ }
+}
+
+// WriteTo will write bytes from buffer into writer, fulfilling io.WriterTo.
+func (buf *Buffer) WriteTo(w io.Writer) (int64, error) {
+ n, err := w.Write(buf.B)
+ return int64(n), err
+}
+
// Len returns the length of the buffer's underlying byte slice.
func (buf *Buffer) Len() int {
return len(buf.B)