Git Product home page Git Product logo

base62-csharp's People

Contributors

renmengye 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

base62-csharp's Issues

Extra 0 byte sometimes added on decode FromBase62()

We found that sometimes we were getting an extra 0 byte back from FromBase62. The following change to EncodingExtensions.cs fixed it:

75c75,79
<                                       stream.Write(new byte[] { (byte)(index << (mod)) }, 0, 8 - mod);

---
>                                       if (mod > 0)
>                                       {
>                                               // only pad with more bits if it didn't come out at an exact byte boundary
>                                               stream.Write(new byte[] {(byte)(index << (mod))}, 0, 8 - mod);
>                                       }

Publish Nuget package on nuget.org

You've published this with an MIT license so I understand I can just copy the code but it would also be nice if I could just include your code in mine thru NuGet.

I'm willing to help out if you're interested and want any help.

Incorrect zero padding on some Guids

I recognize this project is a number of years old, but I wanted to leave a remark for anyone else coming across this just in case. In some cases, when encoding a Guid, the algorithm will pad an erroneous zero to the end. For example:

Guid: b45a57cd-440a-41f4-b57f-fe87c4fca78e
Expected result: pLTQj0f4yY3QlzzGz4zbF7
Actual result: pLTQj0f4yY3QlzzGz4zbF70

When running a unit test with one million iterations, the algorithm failed a number of times, returning an encoded string with a length of 23 rather than the expected length of 22.

Checks for invalid inputs

I think that it would be good to have this validity checks when decoding:

else
{
    // Check if the ending is good
    int mod = (int)(stream.Position % 8);
    if (mod == 0)
        throw new InvalidDataException("an extra character was found");

    if ((index >> (8 - mod)) > 0)
        throw new InvalidDataException("invalid ending character was found");

    stream.Write(new byte[] { (byte)(index << mod) }, 0, 8 - mod);
}

Please can you add a license?

I would like to use this code in a project, but I need a non-GNU license to do so. Can you please add one? MIT would be ideal. Many thanks!

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.