summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/shazow/rateio/reader.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-12-03 01:24:05 +0100
committerWim <wim@42.be>2017-12-03 01:24:05 +0100
commited9118b34620f1ecd5f28506328d4ffe1b04793d (patch)
tree442998012f6779446a463e402fa7c0836edcac91 /vendor/github.com/shazow/rateio/reader.go
parent59e55cfbd5cc3c82236c5e8b95e5baff256f7143 (diff)
downloadmatterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.gz
matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.bz2
matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.zip
Add sshchat dependencies in vendor
Diffstat (limited to 'vendor/github.com/shazow/rateio/reader.go')
-rw-r--r--vendor/github.com/shazow/rateio/reader.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/vendor/github.com/shazow/rateio/reader.go b/vendor/github.com/shazow/rateio/reader.go
new file mode 100644
index 00000000..56bd8ffa
--- /dev/null
+++ b/vendor/github.com/shazow/rateio/reader.go
@@ -0,0 +1,25 @@
+package rateio
+
+import "io"
+
+type reader struct {
+ io.Reader
+ Limiter
+}
+
+// Read reads data into p.
+// Returns ErrRateExceeded error if our specified read is exceeded.
+func (r *reader) Read(p []byte) (n int, err error) {
+ n, err = r.Reader.Read(p)
+ if err != nil {
+ return
+ }
+
+ err = r.Limiter.Count(n)
+ return
+}
+
+// NewReader proxies an io.Reader but keeps track of bytes read based on our Limiter.
+func NewReader(r io.Reader, limiter Limiter) io.Reader {
+ return &reader{r, limiter}
+}