summaryrefslogtreecommitdiff
path: root/vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-07-12 09:39:47 +0000
committerLibravatar GitHub <noreply@github.com>2024-07-12 09:39:47 +0000
commitcde2fb6244a791b3c5b746112e3a8be3a79f39a4 (patch)
tree6079d6fb66d90ffbe8c1623525bb86829c162459 /vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go
parent[chore] Add interaction policy gtsmodels (#3075) (diff)
downloadgotosocial-cde2fb6244a791b3c5b746112e3a8be3a79f39a4.tar.xz
[feature] support processing of (many) more media types (#3090)
* initial work replacing our media decoding / encoding pipeline with ffprobe + ffmpeg * specify the video codec to use when generating static image from emoji * update go-storage library (fixes incompatibility after updating go-iotools) * maintain image aspect ratio when generating a thumbnail for it * update readme to show go-ffmpreg * fix a bunch of media tests, move filesize checking to callers of media manager for more flexibility * remove extra debug from error message * fix up incorrect function signatures * update PutFile to just use regular file copy, as changes are file is on separate partition * fix remaining tests, remove some unneeded tests now we're working with ffmpeg/ffprobe * update more tests, add more code comments * add utilities to generate processed emoji / media outputs * fix remaining tests * add test for opus media file, add license header to utility cmds * limit the number of concurrently available ffmpeg / ffprobe instances * reduce number of instances * further reduce number of instances * fix envparsing test with configuration variables * update docs and configuration with new media-{local,remote}-max-size variables
Diffstat (limited to 'vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go')
-rw-r--r--vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go146
1 files changed, 0 insertions, 146 deletions
diff --git a/vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go b/vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go
deleted file mode 100644
index 5d41bb5df..000000000
--- a/vendor/github.com/dsoprea/go-utility/v2/filesystem/seekable_buffer.go
+++ /dev/null
@@ -1,146 +0,0 @@
-package rifs
-
-import (
- "io"
- "os"
-
- "github.com/dsoprea/go-logging"
-)
-
-// SeekableBuffer is a simple memory structure that satisfies
-// `io.ReadWriteSeeker`.
-type SeekableBuffer struct {
- data []byte
- position int64
-}
-
-// NewSeekableBuffer is a factory that returns a `*SeekableBuffer`.
-func NewSeekableBuffer() *SeekableBuffer {
- data := make([]byte, 0)
-
- return &SeekableBuffer{
- data: data,
- }
-}
-
-// NewSeekableBufferWithBytes is a factory that returns a `*SeekableBuffer`.
-func NewSeekableBufferWithBytes(originalData []byte) *SeekableBuffer {
- data := make([]byte, len(originalData))
- copy(data, originalData)
-
- return &SeekableBuffer{
- data: data,
- }
-}
-
-func len64(data []byte) int64 {
- return int64(len(data))
-}
-
-// Bytes returns the underlying slice.
-func (sb *SeekableBuffer) Bytes() []byte {
- return sb.data
-}
-
-// Len returns the number of bytes currently stored.
-func (sb *SeekableBuffer) Len() int {
- return len(sb.data)
-}
-
-// Write does a standard write to the internal slice.
-func (sb *SeekableBuffer) Write(p []byte) (n int, err error) {
- defer func() {
- if state := recover(); state != nil {
- err = log.Wrap(state.(error))
- }
- }()
-
- // The current position we're already at is past the end of the data we
- // actually have. Extend our buffer up to our current position.
- if sb.position > len64(sb.data) {
- extra := make([]byte, sb.position-len64(sb.data))
- sb.data = append(sb.data, extra...)
- }
-
- positionFromEnd := len64(sb.data) - sb.position
- tailCount := positionFromEnd - len64(p)
-
- var tailBytes []byte
- if tailCount > 0 {
- tailBytes = sb.data[len64(sb.data)-tailCount:]
- sb.data = append(sb.data[:sb.position], p...)
- } else {
- sb.data = append(sb.data[:sb.position], p...)
- }
-
- if tailBytes != nil {
- sb.data = append(sb.data, tailBytes...)
- }
-
- dataSize := len64(p)
- sb.position += dataSize
-
- return int(dataSize), nil
-}
-
-// Read does a standard read against the internal slice.
-func (sb *SeekableBuffer) Read(p []byte) (n int, err error) {
- defer func() {
- if state := recover(); state != nil {
- err = log.Wrap(state.(error))
- }
- }()
-
- if sb.position >= len64(sb.data) {
- return 0, io.EOF
- }
-
- n = copy(p, sb.data[sb.position:])
- sb.position += int64(n)
-
- return n, nil
-}
-
-// Truncate either chops or extends the internal buffer.
-func (sb *SeekableBuffer) Truncate(size int64) (err error) {
- defer func() {
- if state := recover(); state != nil {
- err = log.Wrap(state.(error))
- }
- }()
-
- sizeInt := int(size)
- if sizeInt < len(sb.data)-1 {
- sb.data = sb.data[:sizeInt]
- } else {
- new := make([]byte, sizeInt-len(sb.data))
- sb.data = append(sb.data, new...)
- }
-
- return nil
-}
-
-// Seek does a standard seek on the internal slice.
-func (sb *SeekableBuffer) Seek(offset int64, whence int) (n int64, err error) {
- defer func() {
- if state := recover(); state != nil {
- err = log.Wrap(state.(error))
- }
- }()
-
- if whence == os.SEEK_SET {
- sb.position = offset
- } else if whence == os.SEEK_END {
- sb.position = len64(sb.data) + offset
- } else if whence == os.SEEK_CUR {
- sb.position += offset
- } else {
- log.Panicf("seek whence is not valid: (%d)", whence)
- }
-
- if sb.position < 0 {
- sb.position = 0
- }
-
- return sb.position, nil
-}