diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-13 10:52:26 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-13 10:53:48 +0200 |
commit | 4168e8c6ed41fa4cb53dfded67caed79a82e8789 (patch) | |
tree | 95b970fc2da9ff6cd32710e28c56a31494a6d749 /utils/ioutils.go | |
parent | 13e45db0878bc2dc36ad4578c0758dd05879cded (diff) | |
download | dna-backup-4168e8c6ed41fa4cb53dfded67caed79a82e8789.tar.gz dna-backup-4168e8c6ed41fa4cb53dfded67caed79a82e8789.zip |
add read write wrappers to compress chunks' content
Diffstat (limited to 'utils/ioutils.go')
-rw-r--r-- | utils/ioutils.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/utils/ioutils.go b/utils/ioutils.go new file mode 100644 index 0000000..a861995 --- /dev/null +++ b/utils/ioutils.go @@ -0,0 +1,28 @@ +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 } + +// 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) +} |