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-03-10 01:59:49 +0100
commit3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch)
treef61faa581feaaeaba2542b9f2b8234a590684413 /vendor/codeberg.org/gruf/go-iotools/helpers.go
parent[chore] update URLs to forked source (diff)
downloadgotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.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
-}