refactor: constants io reusable iface
This commit is contained in:
@ -16,12 +16,15 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
// you can download the rosie.unknown image in the link:
|
||||||
// you can download the rosie.unknown image in the link:
|
// https://inancgumus.github.com/x/rosie.unknown
|
||||||
// https://inancgumus.github.com/x/rosie.unknown
|
|
||||||
|
|
||||||
// then feed the file to the standard input of this program:
|
// then feed the file to the standard input of this program:
|
||||||
// go run . < rosie.unknown
|
// 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).
|
// create an in-memory buffer (bytes.Buffer is an io.Reader and an io.Writer).
|
||||||
memory := bytes.Buffer{}
|
memory := bytes.Buffer{}
|
||||||
@ -36,9 +39,8 @@ func main() {
|
|||||||
buf := memory.Bytes()
|
buf := memory.Bytes()
|
||||||
|
|
||||||
// print the first eight bytes.
|
// print the first eight bytes.
|
||||||
fmt.Printf("% x\n", buf[:8])
|
fmt.Printf("% x\n", buf[:pngSignLen])
|
||||||
|
|
||||||
// compare it with the png signature.
|
// compare it with the png signature.
|
||||||
const pngSign = "\x89PNG\r\n\x1a\n"
|
|
||||||
fmt.Printf("% x\n", pngSign)
|
fmt.Printf("% x\n", pngSign)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user