mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
crypto/cipher: StreamWriter.Closer docs + behavior change
Don't panic when the underlying Writer isn't a Closer. And document what Close does and clarify that it's not a Flush. R=golang-dev, agl CC=golang-dev https://golang.org/cl/10310043
This commit is contained in:
parent
d660688f14
commit
14e52c74bc
|
@ -25,6 +25,8 @@ func (r StreamReader) Read(dst []byte) (n int, err error) {
|
||||||
// StreamWriter wraps a Stream into an io.Writer. It calls XORKeyStream
|
// StreamWriter wraps a Stream into an io.Writer. It calls XORKeyStream
|
||||||
// to process each slice of data which passes through. If any Write call
|
// to process each slice of data which passes through. If any Write call
|
||||||
// returns short then the StreamWriter is out of sync and must be discarded.
|
// returns short then the StreamWriter is out of sync and must be discarded.
|
||||||
|
// A StreamWriter has no internal buffering; Close does not need
|
||||||
|
// to be called to flush write data.
|
||||||
type StreamWriter struct {
|
type StreamWriter struct {
|
||||||
S Stream
|
S Stream
|
||||||
W io.Writer
|
W io.Writer
|
||||||
|
@ -43,8 +45,11 @@ func (w StreamWriter) Write(src []byte) (n int, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the underlying Writer and returns its Close return value, if the Writer
|
||||||
|
// is also an io.Closer. Otherwise it returns nil.
|
||||||
func (w StreamWriter) Close() error {
|
func (w StreamWriter) Close() error {
|
||||||
// This saves us from either requiring a WriteCloser or having a
|
if c, ok := w.W.(io.Closer); ok {
|
||||||
// StreamWriterCloser.
|
return c.Close()
|
||||||
return w.W.(io.Closer).Close()
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue