From 8922de6783313ead479aeb0b478808152796d0c4 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 14 Aug 2014 15:50:28 -0400 Subject: [PATCH] updating the example to use the new Marshal and Unmarshal --- example_loader.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/example_loader.go b/example_loader.go index 2a7e309..bc54cee 100644 --- a/example_loader.go +++ b/example_loader.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/vbatts/go-bt/bencode" "github.com/vbatts/go-bt/torrent" + "io/ioutil" "os" ) @@ -27,19 +28,20 @@ func main() { continue } - data, err := bencode.Decode(fh) + buf, err := ioutil.ReadAll(fh) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) - fh.Close() continue } fh.Close() - tf, err := torrent.DecocdeTorrentData(data) + tf := torrent.File{} + err = bencode.Unmarshal(buf, &tf) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) continue } + fmt.Printf("Loaded: %s (%d files)\n", tf.Info.Name, len(tf.Info.Files)) if len(*flOutput) > 0 { @@ -48,7 +50,11 @@ func main() { fmt.Fprintf(os.Stderr, "%s\n", err) continue } - err = bencode.Marshal(fhOutput, *tf) + buf, err = bencode.Marshal(tf) + if err != nil { + fmt.Fprintf(os.Stderr, "%s\n", err) + } + _, err = fhOutput.Write(buf) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) }