From 3ffc6cb0218ecd1868efdb76a4930925097da190 Mon Sep 17 00:00:00 2001 From: n-peugnet Date: Wed, 22 Sep 2021 21:15:29 +0200 Subject: rename and remove unused utils --- utils/fileutils.go | 10 ---------- utils/fileutils_test.go | 15 --------------- utils/io.go | 39 +++++++++++++++++++++++++++++++++++++++ utils/ioutils.go | 39 --------------------------------------- 4 files changed, 39 insertions(+), 64 deletions(-) delete mode 100644 utils/fileutils.go delete mode 100644 utils/fileutils_test.go create mode 100644 utils/io.go delete mode 100644 utils/ioutils.go diff --git a/utils/fileutils.go b/utils/fileutils.go deleted file mode 100644 index 6c269ca..0000000 --- a/utils/fileutils.go +++ /dev/null @@ -1,10 +0,0 @@ -package utils - -import ( - "path/filepath" - "strings" -) - -func TrimTrailingSeparator(path string) string { - return strings.TrimSuffix(path, string(filepath.Separator)) -} diff --git a/utils/fileutils_test.go b/utils/fileutils_test.go deleted file mode 100644 index 176d856..0000000 --- a/utils/fileutils_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package utils - -import ( - "path/filepath" - "testing" -) - -func TestTrimTrailingSeparator(t *testing.T) { - if TrimTrailingSeparator("test"+string(filepath.Separator)) != "test" { - t.Error("Seprator should have been trimmed") - } - if TrimTrailingSeparator("test") != "test" { - t.Error("Path should not have changed") - } -} 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) +} diff --git a/utils/ioutils.go b/utils/ioutils.go deleted file mode 100644 index fcc341e..0000000 --- a/utils/ioutils.go +++ /dev/null @@ -1,39 +0,0 @@ -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) -} -- cgit v1.2.3