github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/core/hexdump/hexdump.go (about) 1 // Copyright 2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // hexdump prints file content in hexadecimal. 6 // 7 // Synopsis: 8 // hexdump [FILES]... 9 // 10 // Description: 11 // Concatenate the input files into a single hexdump. If there are no 12 // arguments, stdin is read. 13 package main 14 15 import ( 16 "encoding/hex" 17 "flag" 18 "io" 19 "log" 20 "os" 21 ) 22 23 func main() { 24 flag.Parse() 25 26 var readers []io.Reader 27 28 if flag.NArg() == 0 { 29 readers = []io.Reader{os.Stdin} 30 } else { 31 readers = make([]io.Reader, 0, flag.NArg()) 32 33 for _, filename := range flag.Args() { 34 f, err := os.Open(filename) 35 if err != nil { 36 log.Fatal(err) 37 } 38 defer f.Close() 39 readers = append(readers, f) 40 } 41 } 42 43 r := io.MultiReader(readers...) 44 w := hex.Dumper(os.Stdout) 45 defer w.Close() 46 47 if _, err := io.Copy(w, r); err != nil { 48 log.Fatal(err) 49 } 50 }