mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
comments
This commit is contained in:
parent
66ebeaa0ca
commit
fcc66704fa
@ -26,12 +26,14 @@ func (w *BufferToBytesWriter) WriteMultiBuffer(mb MultiBuffer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ReadFrom implements io.ReaderFrom.
|
||||
func (w *BufferToBytesWriter) ReadFrom(reader io.Reader) (int64, error) {
|
||||
var sc SizeCounter
|
||||
err := Copy(NewReader(reader), w, CountSize(&sc))
|
||||
return sc.Size, err
|
||||
}
|
||||
|
||||
// BufferedWriter is a Writer with internal buffer.
|
||||
type BufferedWriter struct {
|
||||
writer Writer
|
||||
legacyWriter io.Writer
|
||||
@ -39,6 +41,7 @@ type BufferedWriter struct {
|
||||
buffered bool
|
||||
}
|
||||
|
||||
// NewBufferedWriter creates a new BufferedWriter.
|
||||
func NewBufferedWriter(writer Writer) *BufferedWriter {
|
||||
w := &BufferedWriter{
|
||||
writer: writer,
|
||||
@ -51,6 +54,7 @@ func NewBufferedWriter(writer Writer) *BufferedWriter {
|
||||
return w
|
||||
}
|
||||
|
||||
// Write implements io.Writer.
|
||||
func (w *BufferedWriter) Write(b []byte) (int, error) {
|
||||
if !w.buffered && w.legacyWriter != nil {
|
||||
return w.legacyWriter.Write(b)
|
||||
@ -78,6 +82,7 @@ func (w *BufferedWriter) Write(b []byte) (int, error) {
|
||||
return totalBytes, nil
|
||||
}
|
||||
|
||||
// WriteMultiBuffer implements Writer. It takes ownership of the given MultiBuffer.
|
||||
func (w *BufferedWriter) WriteMultiBuffer(b MultiBuffer) error {
|
||||
if !w.buffered {
|
||||
return w.writer.WriteMultiBuffer(b)
|
||||
@ -99,6 +104,7 @@ func (w *BufferedWriter) WriteMultiBuffer(b MultiBuffer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Flush flushes buffered content into underlying writer.
|
||||
func (w *BufferedWriter) Flush() error {
|
||||
if !w.buffer.IsEmpty() {
|
||||
if err := w.writer.WriteMultiBuffer(NewMultiBufferValue(w.buffer)); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user