summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-byteutil/reader.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-02-18 16:02:19 +0000
committerLibravatar GitHub <noreply@github.com>2023-02-18 17:02:19 +0100
commita684fc46288e38a7e1d3555cb9a5a48b8c65b634 (patch)
tree78f49cdef331979fd7c0bb20f9014515176e9117 /vendor/codeberg.org/gruf/go-byteutil/reader.go
parent[chore]: Bump golang.org/x/net from 0.5.0 to 0.7.0 (#1523) (diff)
downloadgotosocial-a684fc46288e38a7e1d3555cb9a5a48b8c65b634.tar.xz
[chore] transport improvements (#1524)
* improve error readability, mark "bad hosts" as fastFail Signed-off-by: kim <grufwub@gmail.com> * pull in latest go-byteutil version with byteutil.Reader{} Signed-off-by: kim <grufwub@gmail.com> * use rewindable body reader for post requests Signed-off-by: kim <grufwub@gmail.com> --------- Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-byteutil/reader.go')
-rw-r--r--vendor/codeberg.org/gruf/go-byteutil/reader.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-byteutil/reader.go b/vendor/codeberg.org/gruf/go-byteutil/reader.go
new file mode 100644
index 000000000..94c755ff4
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-byteutil/reader.go
@@ -0,0 +1,36 @@
+package byteutil
+
+import "bytes"
+
+// Reader wraps a bytes.Reader{} to provide Rewind() capabilities.
+type Reader struct {
+ B []byte
+ bytes.Reader
+}
+
+// NewReader returns a new Reader{} instance reset to b.
+func NewReader(b []byte) *Reader {
+ r := &Reader{}
+ r.Reset(b)
+ return r
+}
+
+// Reset resets the Reader{} to be reading from b and sets Reader{}.B.
+func (r *Reader) Reset(b []byte) {
+ r.B = b
+ r.Rewind()
+}
+
+// Rewind resets the Reader{} to be reading from the start of Reader{}.B.
+func (r *Reader) Rewind() {
+ r.Reader.Reset(r.B)
+}
+
+// ReadNopCloser wraps a Reader{} to provide nop close method.
+type ReadNopCloser struct {
+ Reader
+}
+
+func (*ReadNopCloser) Close() error {
+ return nil
+}