From acbec476c3205535fa3fac2d1eb2c1e34c88dc5d Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Mon, 4 Nov 2019 12:09:15 +0300 Subject: [PATCH] refactor: constants io reusable iface --- interfaces/14-io-reusable/main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/interfaces/14-io-reusable/main.go b/interfaces/14-io-reusable/main.go index 6413042..0f24f09 100644 --- a/interfaces/14-io-reusable/main.go +++ b/interfaces/14-io-reusable/main.go @@ -16,12 +16,15 @@ import ( "os" ) -func main() { - // you can download the rosie.unknown image in the link: - // https://inancgumus.github.com/x/rosie.unknown +// you can download the rosie.unknown image in the link: +// https://inancgumus.github.com/x/rosie.unknown - // then feed the file to the standard input of this program: - // go run . < rosie.unknown +// then feed the file to the standard input of this program: +// go run . < rosie.unknown + +func main() { + const pngSign = "\x89PNG\r\n\x1a\n" + const pngSignLen = 8 // create an in-memory buffer (bytes.Buffer is an io.Reader and an io.Writer). memory := bytes.Buffer{} @@ -36,9 +39,8 @@ func main() { buf := memory.Bytes() // print the first eight bytes. - fmt.Printf("% x\n", buf[:8]) + fmt.Printf("% x\n", buf[:pngSignLen]) // compare it with the png signature. - const pngSign = "\x89PNG\r\n\x1a\n" fmt.Printf("% x\n", pngSign) }