diff --git a/pkg/util/io/file.go b/pkg/util/io/file.go index f9cc26a5..c7845755 100644 --- a/pkg/util/io/file.go +++ b/pkg/util/io/file.go @@ -69,23 +69,3 @@ func RenamePath(oldPath, newPath string) error { return nil } - -// IsBinary returns true if a zero byte occurs within the first -// 8000 bytes (or the entire length if shorter). This is the -// same approach that git uses to determine if a file is binary. -func IsBinary(bytes []byte) bool { - const firstFewBytes = 8000 - - length := len(bytes) - if firstFewBytes < length { - length = firstFewBytes - } - - for i := 0; i < length; i++ { - if bytes[i] == 0 { - return true - } - } - - return false -} diff --git a/pkg/util/io/io.go b/pkg/util/io/io.go deleted file mode 100644 index 224c919d..00000000 --- a/pkg/util/io/io.go +++ /dev/null @@ -1,36 +0,0 @@ -package io - -import ( - "bufio" - "bytes" - "fmt" - "io" - "os" -) - -// Read stdin content as string -func ReadStdinInput() (string, error) { - // validate - info, err := os.Stdin.Stat() - if err != nil { - return "", err - } - if info.Mode()&os.ModeCharDevice != 0 { - return "", fmt.Errorf("no data read from stdin") - } - - // read content from stdin until EOF is encountered - input := bufio.NewReader(os.Stdin) - output := bytes.NewBuffer([]byte{}) - - for { - b, err := input.ReadByte() - if err == io.EOF { - break - } else if err != nil { - return "", err - } - output.WriteByte(b) - } - return output.String(), nil -} diff --git a/pkg/util/io/io_test.go b/pkg/util/io/io_test.go deleted file mode 100644 index 068d848d..00000000 --- a/pkg/util/io/io_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package io - -import ( - "bufio" - "bytes" - "io" - "os" - "testing" - "time" - - "github.com/bytedance/mockey" - "github.com/stretchr/testify/assert" -) - -func TestReadStdinInput(t *testing.T) { - mockey.PatchConvey("test read stdin input", t, func() { - mockey.Mock((*os.File).Stat).To(func(file *os.File) (os.FileInfo, error) { - return mockInfo{}, nil - }).Build() - input := "hello world!" - mockey.Mock(bufio.NewReader).To(func(rd io.Reader) *bufio.Reader { - return bufio.NewReaderSize(bytes.NewReader([]byte(input)), 4096) - }).Build() - result, err := ReadStdinInput() - assert.Equal(t, input, result) - assert.Nil(t, err) - }) -} - -type mockInfo struct{} - -func (m mockInfo) Name() string { - return "" -} - -func (m mockInfo) Size() int64 { - return 4096 -} - -func (m mockInfo) Mode() os.FileMode { - return os.FileMode(0o777) -} - -func (m mockInfo) IsDir() bool { - return false -} - -func (m mockInfo) Sys() interface{} { - return nil -} - -func (m mockInfo) ModTime() time.Time { - return time.Time{} -}