MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / AsyncBuffer

Struct AsyncBuffer

asyncbuffer/buffer.go:60–78  ·  view source on GitHub ↗

AsyncBuffer is a wrapper around io.Reader that reads data in chunks in background and allows reading from synchronously.

Source from the content-addressed store, hash-verified

58// AsyncBuffer is a wrapper around io.Reader that reads data in chunks
59// in background and allows reading from synchronously.
60type AsyncBuffer struct {
61 r io.ReadCloser // Upstream reader
62 dataLen int // Expected length of the data in r, <= 0 means unknown length
63
64 chunks []*byteChunk // References to the chunks read from the upstream reader
65 mu sync.RWMutex // Mutex on chunks slice
66
67 err atomic.Value // Error that occurred during reading
68 bytesRead atomic.Int64 // Total length of the data read
69
70 finished atomic.Bool // Indicates that the buffer has finished reading
71 closed atomic.Bool // Indicates that the buffer was closed
72
73 paused *Latch // Paused buffer does not read data beyond threshold
74 chunkCond *Cond // Ticker that signals when a new chunk is ready
75
76 finishOnce sync.Once
77 finishFn []context.CancelFunc
78}
79
80// New creates a new AsyncBuffer that reads from the given io.ReadCloser in background
81// and closes it when finished.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected