mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-04 09:17:32 -05:00
36 lines
538 B
Go
36 lines
538 B
Go
package net
|
|
|
|
import (
|
|
"io"
|
|
|
|
_ "github.com/v2ray/v2ray-core/log"
|
|
)
|
|
|
|
const (
|
|
bufferSize = 32 * 1024
|
|
)
|
|
|
|
func ReaderToChan(stream chan<- []byte, reader io.Reader) error {
|
|
for {
|
|
buffer := make([]byte, bufferSize)
|
|
nBytes, err := reader.Read(buffer)
|
|
if nBytes > 0 {
|
|
stream <- buffer[:nBytes]
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ChanToWriter(writer io.Writer, stream <-chan []byte) error {
|
|
for buffer := range stream {
|
|
_, err := writer.Write(buffer)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|