예제 #1
0
파일: term.go 프로젝트: xingskycn/go
// MaskOut masks the output stream forWrites.
//
// WARNING! This uses os pipes, so kernel buffering may cut the tail!
func MaskOut(out *os.File, enc encoding.Encoding) (*os.File, error) {
	pr, pw, err := os.Pipe()
	if err != nil {
		return out, err
	}
	iohlp.SetDirect(pr)
	iohlp.SetDirect(pw)
	// pw -> pr -> out
	go func() {
		defer out.Close()
		io.Copy(text.NewWriter(out, enc), pr)
	}()
	return pw, nil
}
예제 #2
0
파일: term.go 프로젝트: xingskycn/go
// MaskIn masks the input stream for Reads.
func MaskIn(in *os.File, enc encoding.Encoding) (*os.File, error) {
	pr, pw, err := os.Pipe()
	if err != nil {
		return in, err
	}
	iohlp.SetDirect(pr)
	iohlp.SetDirect(pw)
	// in -> pw -> pr
	go func() {
		defer in.Close()
		io.Copy(pw, text.NewReader(in, enc))

	}()
	return pr, nil
}