1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 09:17:32 -05:00
v2fly/net/transport.go

35 lines
572 B
Go
Raw Normal View History

2015-09-13 14:01:50 -04:00
package net
import (
"io"
"github.com/v2ray/v2ray-core/log"
)
const (
bufferSize = 8192
)
func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
for {
buffer := make([]byte, bufferSize)
nBytes, err := reader.Read(buffer)
if err != nil {
return err
}
stream <- buffer[:nBytes]
}
return nil
}
func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
for buffer := range stream {
nBytes, err := writer.Write(buffer)
log.Debug("Writing %d bytes with error %v", nBytes, err)
if err != nil {
return err
}
}
return nil
}