summaryrefslogtreecommitdiff
path: root/vendor/github.com/armon
diff options
context:
space:
mode:
authorJan Unterbrink <jan.unterbrink@subpath.de>2019-07-29 21:49:02 +0200
committerJan Unterbrink <jan.unterbrink@subpath.de>2019-08-08 22:14:55 +0200
commit42bc4722dd3f1320f528fcd84cfb0fae5227315b (patch)
tree2be21e3277a8e8cbdf691bb21290cecadf7da2f0 /vendor/github.com/armon
parentremove dep tarvis stage (diff)
downloadkubeedge-42bc4722dd3f1320f528fcd84cfb0fae5227315b.tar.gz
use vendor
Diffstat (limited to 'vendor/github.com/armon')
-rw-r--r--vendor/github.com/armon/circbuf/LICENSE20
-rw-r--r--vendor/github.com/armon/circbuf/README.md28
-rw-r--r--vendor/github.com/armon/circbuf/circbuf.go92
-rw-r--r--vendor/github.com/armon/circbuf/go.mod1
4 files changed, 141 insertions, 0 deletions
diff --git a/vendor/github.com/armon/circbuf/LICENSE b/vendor/github.com/armon/circbuf/LICENSE
new file mode 100644
index 000000000..106569e54
--- /dev/null
+++ b/vendor/github.com/armon/circbuf/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Armon Dadgar
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/armon/circbuf/README.md b/vendor/github.com/armon/circbuf/README.md
new file mode 100644
index 000000000..f2e356b8d
--- /dev/null
+++ b/vendor/github.com/armon/circbuf/README.md
@@ -0,0 +1,28 @@
+circbuf
+=======
+
+This repository provides the `circbuf` package. This provides a `Buffer` object
+which is a circular (or ring) buffer. It has a fixed size, but can be written
+to infinitely. Only the last `size` bytes are ever retained. The buffer implements
+the `io.Writer` interface.
+
+Documentation
+=============
+
+Full documentation can be found on [Godoc](http://godoc.org/github.com/armon/circbuf)
+
+Usage
+=====
+
+The `circbuf` package is very easy to use:
+
+```go
+buf, _ := NewBuffer(6)
+buf.Write([]byte("hello world"))
+
+if string(buf.Bytes()) != " world" {
+ panic("should only have last 6 bytes!")
+}
+
+```
+
diff --git a/vendor/github.com/armon/circbuf/circbuf.go b/vendor/github.com/armon/circbuf/circbuf.go
new file mode 100644
index 000000000..de3cb94a3
--- /dev/null
+++ b/vendor/github.com/armon/circbuf/circbuf.go
@@ -0,0 +1,92 @@
+package circbuf
+
+import (
+ "fmt"
+)
+
+// Buffer implements a circular buffer. It is a fixed size,
+// and new writes overwrite older data, such that for a buffer
+// of size N, for any amount of writes, only the last N bytes
+// are retained.
+type Buffer struct {
+ data []byte
+ size int64
+ writeCursor int64
+ written int64
+}
+
+// NewBuffer creates a new buffer of a given size. The size
+// must be greater than 0.
+func NewBuffer(size int64) (*Buffer, error) {
+ if size <= 0 {
+ return nil, fmt.Errorf("Size must be positive")
+ }
+
+ b := &Buffer{
+ size: size,
+ data: make([]byte, size),
+ }
+ return b, nil
+}
+
+// Write writes up to len(buf) bytes to the internal ring,
+// overriding older data if necessary.
+func (b *Buffer) Write(buf []byte) (int, error) {
+ // Account for total bytes written
+ n := len(buf)
+ b.written += int64(n)
+
+ // If the buffer is larger than ours, then we only care
+ // about the last size bytes anyways
+ if int64(n) > b.size {
+ buf = buf[int64(n)-b.size:]
+ }
+
+ // Copy in place
+ remain := b.size - b.writeCursor
+ copy(b.data[b.writeCursor:], buf)
+ if int64(len(buf)) > remain {
+ copy(b.data, buf[remain:])
+ }
+
+ // Update location of the cursor
+ b.writeCursor = ((b.writeCursor + int64(len(buf))) % b.size)
+ return n, nil
+}
+
+// Size returns the size of the buffer
+func (b *Buffer) Size() int64 {
+ return b.size
+}
+
+// TotalWritten provides the total number of bytes written
+func (b *Buffer) TotalWritten() int64 {
+ return b.written
+}
+
+// Bytes provides a slice of the bytes written. This
+// slice should not be written to.
+func (b *Buffer) Bytes() []byte {
+ switch {
+ case b.written >= b.size && b.writeCursor == 0:
+ return b.data
+ case b.written > b.size:
+ out := make([]byte, b.size)
+ copy(out, b.data[b.writeCursor:])
+ copy(out[b.size-b.writeCursor:], b.data[:b.writeCursor])
+ return out
+ default:
+ return b.data[:b.writeCursor]
+ }
+}
+
+// Reset resets the buffer so it has no content.
+func (b *Buffer) Reset() {
+ b.writeCursor = 0
+ b.written = 0
+}
+
+// String returns the contents of the buffer as a string
+func (b *Buffer) String() string {
+ return string(b.Bytes())
+}
diff --git a/vendor/github.com/armon/circbuf/go.mod b/vendor/github.com/armon/circbuf/go.mod
new file mode 100644
index 000000000..23362b19b
--- /dev/null
+++ b/vendor/github.com/armon/circbuf/go.mod
@@ -0,0 +1 @@
+module github.com/armon/circbuf