aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/smithy-go/testing/reader.go
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-12-12 21:55:07 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-12-12 22:25:10 +0300
commit4967f99474a4040ba150eb04995de06342252718 (patch)
treec9c118836513a8fab6e9fcfb25be5d404338bca7 /vendor/github.com/aws/smithy-go/testing/reader.go
parent2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de (diff)
downloadydb-4967f99474a4040ba150eb04995de06342252718.tar.gz
YQ Connector: prepare code base for S3 integration
1. Кодовая база Коннектора переписана с помощью Go дженериков так, чтобы добавление нового источника данных (в частности S3 + csv) максимально переиспользовало имеющийся код (чтобы сохранялась логика нарезания на блоки данных, учёт трафика и пр.) 2. API Connector расширено для работы с S3, но ещё пока не протестировано.
Diffstat (limited to 'vendor/github.com/aws/smithy-go/testing/reader.go')
-rw-r--r--vendor/github.com/aws/smithy-go/testing/reader.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/aws/smithy-go/testing/reader.go b/vendor/github.com/aws/smithy-go/testing/reader.go
new file mode 100644
index 0000000000..2589b05cd2
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/testing/reader.go
@@ -0,0 +1,39 @@
+package testing
+
+import (
+ "io"
+ "sync"
+)
+
+// ByteLoop provides an io.ReadCloser that always fills the read byte slice
+// with repeating value, until closed.
+type ByteLoop struct {
+ value byte
+ closed bool
+ mu sync.RWMutex
+}
+
+// Read populates the passed in byte slice with the value the ByteLoop was
+// created with. Returns the size of bytes written. If the reader is closed,
+// io.EOF will be returned.
+func (l *ByteLoop) Read(p []byte) (size int, err error) {
+ l.mu.RLock()
+ defer l.mu.RUnlock()
+ if l.closed {
+ return 0, io.EOF
+ }
+
+ for i := 0; i < len(p); i++ {
+ p[i] = l.value
+ }
+ return len(p), nil
+}
+
+// Close closes the ByteLoop, and prevents any further reading.
+func (l *ByteLoop) Close() error {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ l.closed = true
+
+ return nil
+}