github.com/moreal/bencodex-go@v0.0.0-20231021172012-18277a477d15/cmd/main.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 bencode "github.com/moreal/bencodex-go" 7 "github.com/moreal/bencodex-go/internal/decoder" 8 "io" 9 "os" 10 ) 11 12 func main() { 13 bytes, err := io.ReadAll(os.Stdin) 14 if err != nil { 15 panic(err) 16 } 17 18 decoder := decoder.Decoder{} 19 result, err := decoder.Decode(bytes) 20 if err != nil { 21 panic(err) 22 } 23 24 converted, err := bencodex.ConvertToBencodexJson(result) 25 if err != nil { 26 panic(err) 27 } 28 29 jsonEncoder := json.NewEncoder(os.Stdout) 30 err = jsonEncoder.Encode(converted) 31 if err != nil { 32 fmt.Errorf("%v", err) 33 } 34 }