Giter VIP home page Giter VIP logo

base58-go's Introduction

base58-go

CI Status Go Report Card MIT License release pkg.go.dev

Base58 encoding/decoding package in Go

This is a Go language package for encoding and decoding base58 strings. This package supports multiple encodings, flickr, ripple and bitcoin.

Package Usage

package main

import (
	"fmt"
	"os"

	"github.com/itchyny/base58-go"
)

func main() {
	encoding := base58.FlickrEncoding // or RippleEncoding or BitcoinEncoding

	encoded, err := encoding.Encode([]byte("100"))
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	fmt.Println(string(encoded))

	decoded, err := encoding.Decode(encoded)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	fmt.Println(string(decoded))
}

base58 command

Homebrew

brew install itchyny/tap/base58

Build from source

go install github.com/itchyny/base58-go/cmd/base58@latest

Basic usage

 $ base58
100
2J
100000000
9QwvW
79228162514264337593543950336
5QchsBFApWPVxyp9C
^D
 $ base58 --decode
2J
100
9QwvW
100000000
5QchsBFApWPVxyp9C
79228162514264337593543950336
^D
 $ echo 100000000 | base58
9QwvW
 $ echo 9QwvW | base58 --decode
100000000
 $ echo 100000000 | base58 --encoding=bitcoin
9qXWw

Bug Tracker

Report bug at Issues・itchyny/base58-go - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

base58-go's People

Contributors

itchyny avatar koron avatar syohex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

base58-go's Issues

Build releases with tinygo for more reasonable size

Megabytes just seem a little big for a tool that manipulates strings to convert between a base number systems. Yeah, there's infinite space and infinite bandwidth these days but... still, just feels wrong. Y'know?
(and looks suspicious to the non-webdev, sysadmin types)

Anyway, if you compile with tinygo, the file size goes down, almost to a reasonable level.

TinyGo Sizes

Note: -tags appengine is used to prevent the unnecessary use of syscalls, which otherwise causes tinygo to fail.

tinygo build -o ./base58 -tags appengine ./cmd/base58/main.go
gzip --keep ./base58
tar cvzf base58.tar.gz ./base58
xz --keep ./base58
zip 'base58' ./base58
ls -lAhF ./base58*
.rwxr-xr-x aj staff 498 KB Fri May  3 21:43:42 2024 ./base58*
.rwxr-xr-x aj staff 155 KB Fri May  3 21:43:42 2024 ./base58.gz*
.rw-r--r-- aj wheel 155 KB Fri May  3 21:43:42 2024 ./base58.tar.gz
.rwxr-xr-x aj staff 115 KB Fri May  3 21:43:42 2024 ./base58.xz*
.rw-r--r-- aj wheel 156 KB Fri May  3 21:43:42 2024 ./base58.zip

Using flag

Unsurprisingly, the custom flag package is the majority of the weight. Replacing that with the standard library's flag cuts the size by nearly half again:

.rwxr-xr-x aj staff 293 KB Fri May  3 21:51:11 2024 ./base58*
.rwxr-xr-x aj staff 103 KB Fri May  3 21:51:11 2024 ./base58.gz*
.rw-r--r-- aj wheel 103 KB Fri May  3 21:51:11 2024 ./base58.tar.gz
.rwxr-xr-x aj staff  78 KB Fri May  3 21:51:11 2024 ./base58.xz*
.rw-r--r-- aj wheel 103 KB Fri May  3 21:51:11 2024 ./base58.zip

That's just the same as about any other unix utility - twice the size of cp and the same size as dash on macOS.

Current Go Sizes

Go's runtime is really huge because of the advanced 0-pause garbage collector that ships even when a simple garbage collector will do. Reflection can also bloat the size.

go build -tags appengine -ldflags '-s -w' -o ./base58 ./cmd/base58/
gzip --keep ./base58
tar cvzf base58.tar.gz ./base58
xz --keep ./base58
zip 'base58' ./base58
ls -lAhF ./base58*
.rwxr-xr-x aj staff 1.7 MB Fri May  3 21:40:40 2024 ./base58*
.rwxr-xr-x aj staff 716 KB Fri May  3 21:40:40 2024 ./base58.gz*
.rw-r--r-- aj wheel 716 KB Fri May  3 21:42:37 2024 ./base58.tar.gz
.rwxr-xr-x aj staff 547 KB Fri May  3 21:40:40 2024 ./base58.xz*
.rw-r--r-- aj wheel 717 KB Fri May  3 21:40:58 2024 ./base58.zip

[RESEARCH] Arbitrary input

Dear @itchyny,
It seems your encoder is currently not able to process arbitrary input as follows

$ type flower.jpg | base58
expecting a number but got "\x1c\x18\xfb\x95\xc3Jt\xbf\xc6\x0f\xe7)J\x04\x1c\x1e[\x83D\x02u\xfe̴k\xccG-\x04\x9e\x1c!\x90\xa3\x9fX\xc8\x02\xae\xd7;\x03\xe3\x0062\xfe\xce\a\xef\x01\r\x98\x0fXV\xc7\x193}g)\xe75\xe5\x0f\x05\xe5\xc0\x06\x9e\xba\xb7(/\x1a\xc1.J\xec\x89\xe6q\xff\x00\xee-P\x1a\xd0\xe0\x0e\x0f\x97\xf1\x8bû\x10\x9f\x98\xa7\xdb\x05x pX\xb9\x94m\xdf\xc6"

What do you think about that? Would it be possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.