diff options
author | 2022-05-08 19:49:45 +0200 | |
---|---|---|
committer | 2022-05-08 18:49:45 +0100 | |
commit | 5004e0a9da665ccc0e18cd4075ee636641b71f0a (patch) | |
tree | b7c8269b954ced61afa9fffd7305bd88acca6f8e /vendor/codeberg.org/gruf/go-byteutil | |
parent | [bugfix] Fix existing bio text showing as HTML (#531) (diff) | |
download | gotosocial-5004e0a9da665ccc0e18cd4075ee636641b71f0a.tar.xz |
[bugfix] Fix remote media pruning failing if media already gone (#548)
* fix error check of prune to allow missing files
* update go-store library, add test for pruning item with db entry but no file
Signed-off-by: kim <grufwub@gmail.com>
* remove now-unneccessary error check
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-byteutil')
-rw-r--r-- | vendor/codeberg.org/gruf/go-byteutil/LICENSE | 9 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-byteutil/README.md | 3 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-byteutil/buffer.go | 129 | ||||
-rw-r--r-- | vendor/codeberg.org/gruf/go-byteutil/bytes.go | 65 |
4 files changed, 206 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-byteutil/LICENSE b/vendor/codeberg.org/gruf/go-byteutil/LICENSE new file mode 100644 index 000000000..e4163ae35 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-byteutil/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2022 gruf + +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/codeberg.org/gruf/go-byteutil/README.md b/vendor/codeberg.org/gruf/go-byteutil/README.md new file mode 100644 index 000000000..e1f81d969 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-byteutil/README.md @@ -0,0 +1,3 @@ +# go-byteutil + +A useful package of byte utilities.
\ No newline at end of file diff --git a/vendor/codeberg.org/gruf/go-byteutil/buffer.go b/vendor/codeberg.org/gruf/go-byteutil/buffer.go new file mode 100644 index 000000000..75b4c61c7 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-byteutil/buffer.go @@ -0,0 +1,129 @@ +package byteutil + +import ( + "errors" + "io" + "unicode/utf8" +) + +var ( + // ensure we conform to interfaces. + _ interface { + io.Writer + io.ByteWriter + WriteRune(rune) (int, error) + io.StringWriter + io.WriterAt + WriteStringAt(string, int64) (int, error) + } = (*Buffer)(nil) + + // ErrBeyondBufferLen is returned if .WriteAt() is attempted beyond buffer length. + ErrBeyondBufferLen = errors.New("start beyond buffer length") +) + +// Buffer is a simple wrapper around a byte slice. +type Buffer struct{ B []byte } + +// WriteByte will append given byte to buffer, fulfilling io.ByteWriter. +func (buf *Buffer) WriteByte(c byte) error { + buf.B = append(buf.B, c) + return nil +} + +// WriteRune will append given rune to buffer. +func (buf *Buffer) WriteRune(r rune) (int, error) { + // Check for single-byte rune + if r < utf8.RuneSelf { + buf.B = append(buf.B, byte(r)) + return 1, nil + } + + // Before-len + l := len(buf.B) + + // Grow to max size rune + buf.Grow(utf8.UTFMax) + + // Write encoded rune to buffer + n := utf8.EncodeRune(buf.B[l:len(buf.B)], r) + buf.B = buf.B[:l+n] + + return n, nil +} + +// Write will append given byte slice to buffer, fulfilling io.Writer. +func (buf *Buffer) Write(b []byte) (int, error) { + buf.B = append(buf.B, b...) + return len(b), nil +} + +// WriteString will append given string to buffer, fulfilling io.StringWriter. +func (buf *Buffer) WriteString(s string) (int, error) { + buf.B = append(buf.B, s...) + return len(s), nil +} + +// WriteAt will append given byte slice to buffer at index 'start', fulfilling io.WriterAt. +func (buf *Buffer) WriteAt(b []byte, start int64) (int, error) { + if start > int64(len(buf.B)) { + return 0, ErrBeyondBufferLen + } + buf.Grow(len(b) - int(int64(len(buf.B))-start)) + return copy(buf.B[start:], b), nil +} + +// WriteStringAt will append given string to buffer at index 'start'. +func (buf *Buffer) WriteStringAt(s string, start int64) (int, error) { + if start > int64(len(buf.B)) { + return 0, ErrBeyondBufferLen + } + buf.Grow(len(s) - int(int64(len(buf.B))-start)) + return copy(buf.B[start:], s), nil +} + +// Len returns the length of the buffer's underlying byte slice. +func (buf *Buffer) Len() int { + return len(buf.B) +} + +// Cap returns the capacity of the buffer's underlying byte slice. +func (buf *Buffer) Cap() int { + return cap(buf.B) +} + +// Grow will increase the buffers length by 'sz', and the capacity by at least this. +func (buf *Buffer) Grow(sz int) { + buf.Guarantee(sz) + buf.B = buf.B[:len(buf.B)+sz] +} + +// Guarantee will guarantee buffer containers at least 'sz' remaining capacity. +func (buf *Buffer) Guarantee(sz int) { + if sz > cap(buf.B)-len(buf.B) { + nb := make([]byte, 2*cap(buf.B)+sz) + copy(nb, buf.B) + buf.B = nb[:len(buf.B)] + } +} + +// Truncate will reduce the length of the buffer by 'n'. +func (buf *Buffer) Truncate(n int) { + if n > len(buf.B) { + n = len(buf.B) + } + buf.B = buf.B[:len(buf.B)-n] +} + +// Reset will reset the buffer length to 0 (retains capacity). +func (buf *Buffer) Reset() { + buf.B = buf.B[:0] +} + +// String returns the underlying byte slice as a string. Please note +// this value is tied directly to the underlying byte slice, if you +// write to the buffer then returned string values will also change. +// +// To get an immutable string from buffered data, use string(buf.B). +func (buf *Buffer) String() string { + return B2S(buf.B) +} diff --git a/vendor/codeberg.org/gruf/go-byteutil/bytes.go b/vendor/codeberg.org/gruf/go-byteutil/bytes.go new file mode 100644 index 000000000..4fbfe001d --- /dev/null +++ b/vendor/codeberg.org/gruf/go-byteutil/bytes.go @@ -0,0 +1,65 @@ +package byteutil + +import ( + "reflect" + "unsafe" +) + +// Copy returns a copy of []byte. +func Copy(b []byte) []byte { + if b == nil { + return nil + } + p := make([]byte, len(b)) + copy(p, b) + return p +} + +// B2S returns a string representation of []byte without allocation. +func B2S(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) +} + +// S2B returns a []byte representation of string without allocation (minus slice header). +func S2B(s string) []byte { + var b []byte + + // Get byte + string headers + bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) + + // Manually set bytes to string + bh.Data = sh.Data + bh.Len = sh.Len + bh.Cap = sh.Len + + return b +} + +// ToUpper offers a faster ToUpper implementation using a lookup table. +func ToUpper(b []byte) { + const toUpperTable = "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" + + " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~" + + "\u007f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96" + + "\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8" + + "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1" + + "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" + for i := 0; i < len(b); i++ { + b[i] = toUpperTable[b[i]] + } +} + +// ToLower offers a faster ToLower implementation using a lookup table. +func ToLower(b []byte) { + const toLowerTable = "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" + + " !\"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" + + "\u007f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96" + + "\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8" + + "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1" + + "\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" + for i := 0; i < len(b); i++ { + b[i] = toLowerTable[b[i]] + } +} |