Coder Social home page Coder Social logo

go-bytesize's Introduction

ByteSize

Bytesize is a package for working with measurements of bytes. Using this package allows you to easily add 100KB to 4928MB and get a nicely formatted string representation of the result.

Go Reference Build Status Coverage Status

Usage

Check the built in documentation for examples using the godoc link above or by running godoc locally.

go-bytesize's People

Contributors

glados28 avatar inhies avatar kellrott avatar kishaningithub avatar maltej avatar zepatrik 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

Watchers

 avatar  avatar

go-bytesize's Issues

Missing support of bytesize with decimals

Hi @inhies,

First of all many thanks for your work.

When you a have big unit like MB, GB, etc you coul want to parse some bytesize like:

  • 440.8MB
  • 220.45TB

But here :

if !unicode.IsDigit(r) {

You only match digit.

This can be easly fixed unsing something like this:

	if !unicode.IsDigit(r) && r != '.'

Thanks !

Support differences of -ga an -bi bytes (Gigabyte/GB, Gibibyte/GiB)

I've noticed that in this repository, gigabytes are defined as 1073741824 bytes. Most people think this is the case, however as defined by SI this should be exactly 1e+9 bytes. This subtle difference can be very confusing.

The problem with this change would be backwards compatibility, as people will be expecting GB to be 1073741824 bytes and KB to be 1024, etc. I'm not sure how to tackle this yet. For example, a new package could be created or a new Format function could be created (name to be determined, something like FormatSI?) that keeps this in mind.

I'll take a look at the source code soon to see whether it is any trivial to create a PR for this by myself.

It is also the question whether people really need this technically correct implementation. The fact that there has been no such issue for however long this package exists might say something about the willingness of people to use SI correct units in programming.

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.