This is a creation in Article, where the information may have evolved or changed.
Contents of binary file:
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F00000000 12 31 23 12 31 22 31 23 12 31 22 22 22 22 22 22 # 1 "1" "" "" "00000010 22 22 22 12 23 12 23 00 00 00 00 00 00 00 00 00" "" # # 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000 070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00000080 00 00 00 00 00 00 00 00 00 00 00 00 0 0 xx, 00000090, xx, xx, xx, 000000a0 00 0 0 xx, xx, xx, xx 000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 000000C0, XX, xx, xx, 000000d0 00 00 00 00 00 00 00 00 00 00 00 00 0 0 00 00 00
Code:
Package Mainimport ("bytes" "FMT" "IO" "OS") Func main () {file, err: = OS. OpenFile ("Test", OS. O_rdonly, OS. MODEPERM) If err! = Nil {defer file. Close () OS. Exit (0)}file. Seek (8, 0) fmt. Println ("Success Open File") var buffer bytes. Bufferio.copyn (&buffer, file, 8) _bytes: = buffer. Bytes () var magic []byte = []byte{0x12, 0x31, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22}for _, Byte: = Range _bytes {fmt. Printf ("%02x", "byte")}fmt. Println () If Bytes.compare (Magic, _bytes) = = 0 {fmt. Println ("Equal")}}
Results:
Success Open File12-Equal