1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 02:16:11 -04:00
v2fly/common/io/writer.go

30 lines
497 B
Go
Raw Normal View History

2016-02-01 06:22:29 -05:00
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
}