GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - marksamman/bencode: Bencode implementation in Go

BranchesTags
Open more actions menu

Latest commit

 

History

29 Commits
29 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
decoder.go
decoder.go
 
 
decoder_test.go
decoder_test.go
 
 
encoder.go
encoder.go
 
 
encoder_test.go
encoder_test.go
 
 

Repository files navigation

bencode Build Status

Bencode implementation in Go

Install

$ go get github.com/marksamman/bencode

Usage

Encode

bencode.Encode takes a map[string]interface{} as argument and returns a byte array. Example:

package main

import (
	"fmt"

	"github.com/marksamman/bencode"
)

func main() {
	dict := make(map[string]interface{})
	dict["string key"] = "hello world"
	dict["int key"] = 123456
	fmt.Printf("bencode encoded dict: %s\n", bencode.Encode(dict))
}

Decode

bencode.Decode takes an io.Reader as argument and returns (map[string]interface{}, error). Example:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/marksamman/bencode"
)

func main() {
	file, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	dict, err := bencode.Decode(file)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("string: %s\n", dict["string key"].(string))
	fmt.Printf("int: %d\n", dict["int key"].(int64))
}

About

Bencode implementation in Go

Resources

Readme
MIT license
Activity

Stars

63 stars

Watchers

2 watching

Forks

12 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.