diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-06-03 17:18:53 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-06-03 17:18:53 +0000 |
| commit | f57081ab0fbda8b7e48384f1830b09f6cb8d3c44 (patch) | |
| tree | e2917d5ecc8e5c45b06fa6f1547ec41812834baa | |
| parent | 3a6e39f8a82299f21b1efa8aaa9a1ea748d25628 (diff) | |
| download | bittorrent-go-f57081ab0fbda8b7e48384f1830b09f6cb8d3c44.tar.gz bittorrent-go-f57081ab0fbda8b7e48384f1830b09f6cb8d3c44.zip | |
codecrafters submit [skip ci]
| -rw-r--r-- | cmd/mybittorrent/main.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/cmd/mybittorrent/main.go b/cmd/mybittorrent/main.go index 5c2a12f..87095ae 100644 --- a/cmd/mybittorrent/main.go +++ b/cmd/mybittorrent/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "strconv" + "strings" "unicode" // bencode "github.com/jackpal/bencode-go" // Available if you need it! ) @@ -28,6 +29,8 @@ func decodeBencode(bencodedString string) (interface{}, error) { } return bencodedString[firstColonIndex+1 : firstColonIndex+1+length], nil + } else if rune(bencodedString[0]) == 'i' { + return strconv.Atoi(bencodedString[1:strings.IndexByte(bencodedString, 'e')]) } else { return "", fmt.Errorf("only strings are supported at the moment") } |