1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 09:57:04 -04:00
v2fly/common/io/writer.go
2016-02-01 12:22:29 +01:00

30 lines
497 B
Go

package io
import (
"io"
"github.com/v2ray/v2ray-core/common/alloc"
)
type Writer interface {
Write(*alloc.Buffer) error
}
type AdaptiveWriter struct {
writer io.Writer
}
func NewAdaptiveWriter(writer io.Writer) *AdaptiveWriter {
return &AdaptiveWriter{
writer: writer,
}
}
func (this *AdaptiveWriter) Write(buffer *alloc.Buffer) error {
nBytes, err := this.writer.Write(buffer.Value)
if nBytes < buffer.Len() {
_, err = this.writer.Write(buffer.Value[nBytes:])
}
return err
}