Skip to content

Commit

Permalink
add sioutil package
Browse files Browse the repository at this point in the history
This commit introduces the `sioutil` package.
It contains just a `NopCloser` method that is
related to https://golang.org/pkg/io/ioutil/#NopCloser.

It wraps a io.Writer and returns a io.WriteCloser that
does nothing on Close().
This is useful when en/decrypting an io.Writer but completing
the en/decryption process should not close the sink.

For example:
```
ew := s.EncryptWriter(sioutil.NopCloser(w), nonce, associatedData)
defer ew.Close() // This does not close 'w'.
```

updates #7
  • Loading branch information
Andreas Auernhammer committed May 28, 2019
1 parent 123cf8d commit 3fae002
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ before_script:
script:
- diff -au <(gofmt -d .) <(printf "")
- diff -au <(go vet .) <(printf "")
- go test
- go test -sio.BufSize=23 -sio.PlaintextSize=1825
- go test ./...
- go test -sio.BufSize=23 -sio.PlaintextSize=1825 ./...
22 changes: 22 additions & 0 deletions sioutil/sio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2019 Andreas Auernhammer. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.

// Package sioutil implements some I/O utility functions.
package sioutil

import (
"io"
)

type nopCloser struct {
io.Writer
}

func (nopCloser) Close() error { return nil }

// NopCloser returns a WriteCloser with a no-op Close method
// wrapping the provided Writer w.
func NopCloser(w io.Writer) io.WriteCloser {
return nopCloser{w}
}

0 comments on commit 3fae002

Please sign in to comment.