mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 20:54:02 +03:00
REPOSITORY / ScuroNeko/mtg
Compare commits
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28fe63dbdb | ||
|
|
7718f62477 | ||
|
|
df0994dad3 | ||
|
|
dca43853fb | ||
|
|
ea8e31346c | ||
|
|
4aab3b686c | ||
|
|
ed495b3800 | ||
|
|
4025f223c4 | ||
|
|
121200cfad | ||
|
|
a8c4d0a9c4 | ||
|
|
790bf21166 | ||
|
|
e5b9c841cd | ||
|
|
8ccf61c23e | ||
|
|
0e033b59b3 | ||
|
|
cdd93bd25f | ||
|
|
cac476901d | ||
|
|
bb21bf814f | ||
|
|
68e1d66017 |
@@ -125,7 +125,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
pull: true
|
pull: true
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64,linux/386
|
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# BUILD STAGE
|
# BUILD STAGE
|
||||||
|
|
||||||
FROM golang:1.15-alpine AS build
|
FROM golang:1.16-alpine AS build
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk --no-cache --update add \
|
&& apk --no-cache --update add \
|
||||||
|
|||||||
+12
-34
@@ -2,7 +2,6 @@ package stream
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -18,10 +17,10 @@ type ReadWriteCloseRewinder interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type wrapperRewind struct {
|
type wrapperRewind struct {
|
||||||
parent conntypes.StreamReadWriteCloser
|
parent conntypes.StreamReadWriteCloser
|
||||||
buf bytes.Buffer
|
activeReader io.Reader
|
||||||
mutex sync.Mutex
|
buf bytes.Buffer
|
||||||
rewinded bool
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wrapperRewind) Write(p []byte) (int, error) {
|
func (w *wrapperRewind) Write(p []byte) (int, error) {
|
||||||
@@ -36,38 +35,14 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
|
|||||||
w.mutex.Lock()
|
w.mutex.Lock()
|
||||||
defer w.mutex.Unlock()
|
defer w.mutex.Unlock()
|
||||||
|
|
||||||
if w.rewinded {
|
return w.activeReader.Read(p)
|
||||||
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
|
|
||||||
return n, err // nolint: wrapcheck
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := w.parent.Read(p)
|
|
||||||
|
|
||||||
if !w.rewinded {
|
|
||||||
w.buf.Write(p[:n])
|
|
||||||
}
|
|
||||||
|
|
||||||
return n, err // nolint: wrapcheck
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
|
func (w *wrapperRewind) ReadTimeout(p []byte, _ time.Duration) (int, error) {
|
||||||
w.mutex.Lock()
|
w.mutex.Lock()
|
||||||
defer w.mutex.Unlock()
|
defer w.mutex.Unlock()
|
||||||
|
|
||||||
if w.rewinded {
|
return w.activeReader.Read(p)
|
||||||
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
|
|
||||||
return n, err // nolint: wrapcheck
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n, err := w.parent.ReadTimeout(p, timeout)
|
|
||||||
|
|
||||||
if !w.rewinded {
|
|
||||||
w.buf.Write(p[:n])
|
|
||||||
}
|
|
||||||
|
|
||||||
return n, err // nolint: wrapcheck
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wrapperRewind) Conn() net.Conn {
|
func (w *wrapperRewind) Conn() net.Conn {
|
||||||
@@ -94,12 +69,15 @@ func (w *wrapperRewind) Close() error {
|
|||||||
|
|
||||||
func (w *wrapperRewind) Rewind() {
|
func (w *wrapperRewind) Rewind() {
|
||||||
w.mutex.Lock()
|
w.mutex.Lock()
|
||||||
w.rewinded = true
|
w.activeReader = io.MultiReader(&w.buf, w.parent)
|
||||||
w.mutex.Unlock()
|
w.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRewind(parent conntypes.StreamReadWriteCloser) ReadWriteCloseRewinder {
|
func NewRewind(parent conntypes.StreamReadWriteCloser) ReadWriteCloseRewinder {
|
||||||
return &wrapperRewind{
|
rv := &wrapperRewind{
|
||||||
parent: parent,
|
parent: parent,
|
||||||
}
|
}
|
||||||
|
rv.activeReader = io.TeeReader(parent, &rv.buf)
|
||||||
|
|
||||||
|
return rv
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user