summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-iotools/helpers.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-12-01 22:08:04 +0100
commitb1af8fd87760b34e3ff2fd3bda38f211815a0473 (patch)
tree9317fad1a7ec298d7a8d2678e4e422953bbc6f33 /vendor/codeberg.org/gruf/go-iotools/helpers.go
parent[chore] update URLs to forked source (diff)
downloadgotosocial-b1af8fd87760b34e3ff2fd3bda38f211815a0473.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/codeberg.org/gruf/go-iotools/helpers.go')
-rw-r--r--vendor/codeberg.org/gruf/go-iotools/helpers.go85
1 files changed, 0 insertions, 85 deletions
diff --git a/vendor/codeberg.org/gruf/go-iotools/helpers.go b/vendor/codeberg.org/gruf/go-iotools/helpers.go
deleted file mode 100644
index 0e50e05e0..000000000
--- a/vendor/codeberg.org/gruf/go-iotools/helpers.go
+++ /dev/null
@@ -1,85 +0,0 @@
-package iotools
-
-import "io"
-
-// AtEOF returns true when reader at EOF,
-// this is checked with a 0 length read.
-func AtEOF(r io.Reader) bool {
- _, err := r.Read(nil)
- return (err == io.EOF)
-}
-
-// GetReadCloserLimit attempts to cast io.Reader to access its io.LimitedReader with limit.
-func GetReaderLimit(r io.Reader) (*io.LimitedReader, int64) {
- lr, ok := r.(*io.LimitedReader)
- if !ok {
- return nil, -1
- }
- return lr, lr.N
-}
-
-// UpdateReaderLimit attempts to update the limit of a reader for existing, newly wrapping if necessary.
-func UpdateReaderLimit(r io.Reader, limit int64) (*io.LimitedReader, int64) {
- lr, ok := r.(*io.LimitedReader)
- if !ok {
- lr = &io.LimitedReader{r, limit}
- return lr, limit
- }
-
- if limit < lr.N {
- // Update existing.
- lr.N = limit
- }
-
- return lr, lr.N
-}
-
-// GetReadCloserLimit attempts to unwrap io.ReadCloser to access its io.LimitedReader with limit.
-func GetReadCloserLimit(rc io.ReadCloser) (*io.LimitedReader, int64) {
- rct, ok := rc.(*ReadCloserType)
- if !ok {
- return nil, -1
- }
- lr, ok := rct.Reader.(*io.LimitedReader)
- if !ok {
- return nil, -1
- }
- return lr, lr.N
-}
-
-// UpdateReadCloserLimit attempts to update the limit of a readcloser for existing, newly wrapping if necessary.
-func UpdateReadCloserLimit(rc io.ReadCloser, limit int64) (io.ReadCloser, *io.LimitedReader, int64) {
-
- // Check for our wrapped ReadCloserType.
- if rct, ok := rc.(*ReadCloserType); ok {
-
- // Attempt to update existing wrapped limit reader.
- if lr, ok := rct.Reader.(*io.LimitedReader); ok {
-
- if limit < lr.N {
- // Update existing.
- lr.N = limit
- }
-
- return rct, lr, lr.N
- }
-
- // Wrap the reader type with new limit.
- lr := &io.LimitedReader{rct.Reader, limit}
- rct.Reader = lr
-
- return rct, lr, lr.N
- }
-
- // Wrap separated types.
- rct := &ReadCloserType{
- Reader: rc,
- Closer: rc,
- }
-
- // Wrap separated reader part with limit.
- lr := &io.LimitedReader{rct.Reader, limit}
- rct.Reader = lr
-
- return rct, lr, lr.N
-}