aboutsummaryrefslogtreecommitdiff
path: root/utils/io.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-22 21:15:29 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-22 21:15:29 +0200
commit3ffc6cb0218ecd1868efdb76a4930925097da190 (patch)
tree1702a13f4daeda6d0c8f321125bfc428a3d2817d /utils/io.go
parent237f6af4dc74183cf76898ff8f471ab3cb786116 (diff)
downloaddna-backup-3ffc6cb0218ecd1868efdb76a4930925097da190.tar.gz
dna-backup-3ffc6cb0218ecd1868efdb76a4930925097da190.zip
rename and remove unused utils
Diffstat (limited to 'utils/io.go')
-rw-r--r--utils/io.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/utils/io.go b/utils/io.go
new file mode 100644
index 0000000..fcc341e
--- /dev/null
+++ b/utils/io.go
@@ -0,0 +1,39 @@
+package utils
+
+import (
+ "compress/zlib"
+ "io"
+)
+
+// 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}
+}
+
+type nopCloser struct {
+ io.Writer
+}
+
+func (nopCloser) Close() error { return nil }
+
+type ReadWrapper func(r io.Reader) (io.ReadCloser, error)
+type WriteWrapper func(w io.Writer) io.WriteCloser
+
+// ZlibReader wraps a reader with a new zlib.Reader.
+func ZlibReader(r io.Reader) (io.ReadCloser, error) {
+ return zlib.NewReader(r)
+}
+
+// ZlibWrier wraps a writer with a new zlib.Writer.
+func ZlibWriter(w io.Writer) io.WriteCloser {
+ return zlib.NewWriter(w)
+}
+
+func NopReadWrapper(r io.Reader) (io.ReadCloser, error) {
+ return io.NopCloser(r), nil
+}
+
+func NopWriteWrapper(w io.Writer) io.WriteCloser {
+ return NopCloser(w)
+}