Skip to content

Commit

Permalink
✨ up(stdio): add new func WriteString, WriteBytes for write to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 4, 2023
1 parent 39019ad commit b40b237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions stdio/stdio.go
Expand Up @@ -5,6 +5,7 @@ import (
"bufio"
"bytes"
"io"
"os"
"strings"
)

Expand Down Expand Up @@ -59,3 +60,13 @@ func NewScanner(in any) *bufio.Scanner {
panic("invalid input type for create scanner")
}
}

// WriteBytes to stdout
func WriteBytes(bs []byte) {
_, _ = os.Stdout.Write(bs)
}

// WriteString to stdout
func WriteString(s string) {
_, _ = os.Stdout.WriteString(s)
}
3 changes: 3 additions & 0 deletions stdio/writer.go
Expand Up @@ -33,6 +33,9 @@ func (w *WriteWrapper) WriteByte(c byte) error {

// WriteString data
func (w *WriteWrapper) WriteString(s string) (n int, err error) {
if sw, ok := w.Out.(io.StringWriter); ok {
return sw.WriteString(s)
}
return w.Out.Write([]byte(s))
}

Expand Down

0 comments on commit b40b237

Please sign in to comment.