我试图读取就是BEING柏油,流媒体,以标准输入存档,但我不知怎么读 远远 在管道的数据超过焦油发送。
我这样运行我的命令:
tar -cf - somefolder | ./my-go-binary
源代码是这样的:
package main
import (
"bufio"
"io"
"log"
"os"
)
// Read from standard input
func main() {
reader := bufio.NewReader(os.Stdin)
// Read all data from stdin, processing subsequent reads as chunks.
parts := 0
for {
parts++
data := make([]byte, 4<<20) // Read 4MB at a time
_, err := reader.Read(data)
if err == io.EOF {
break
} else if err != nil {
log.Fatalf("Problems reading from input: %s", err)
}
}
log.Printf("Total parts processed: %d\n", parts)
}
data
[]byte
os.Stdin