diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2013-06-17 07:30:04 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2013-06-17 07:30:04 -0700 |
| commit | 14e52c74bc7492098ea630bc84514fb427ef8bd9 (patch) | |
| tree | 9f6160820135ddb1cc437731a3fb031353ef8ea2 /src/pkg/crypto | |
| parent | d660688f14baf29a84d1d7cbeea9eae92c15c60f (diff) | |
| download | go-14e52c74bc7492098ea630bc84514fb427ef8bd9.tar.xz | |
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
Diffstat (limited to 'src/pkg/crypto')
| -rw-r--r-- | src/pkg/crypto/cipher/io.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/pkg/crypto/cipher/io.go b/src/pkg/crypto/cipher/io.go index 807e8daeaf..3938c0a4c8 100644 --- a/src/pkg/crypto/cipher/io.go +++ b/src/pkg/crypto/cipher/io.go @@ -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 // 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. +// A StreamWriter has no internal buffering; Close does not need +// to be called to flush write data. type StreamWriter struct { S Stream W io.Writer @@ -43,8 +45,11 @@ func (w StreamWriter) Write(src []byte) (n int, err error) { 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 { - // This saves us from either requiring a WriteCloser or having a - // StreamWriterCloser. - return w.W.(io.Closer).Close() + if c, ok := w.W.(io.Closer); ok { + return c.Close() + } + return nil } |
