Пример #1
0
// 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
// 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
}