Golang encoding/hex.Dumper() function example

package encoding/hex

Dumper returns a WriteCloser that writes a hex dump of all written data to w (1st parameter). The format of the dump matches the output of hexdump -C on the command line.

Golang encoding/hex.Dumper() function usage example

 package main

 import (
 "bytes"
 "encoding/hex"
 "fmt"
 )

 func main() {
 var buff bytes.Buffer

 str := []byte("abcd")

 dumper := hex.Dumper(&buff)
 dumper.Write(str)
 dumper.Close()

 fmt.Println(string(buff.Bytes()))

 }

Output :

00000000 61 62 63 64 |abcd|

Reference :

http://golang.org/pkg/encoding/hex/#Dumper

Advertisement