renmengye / base62-csharp Goto Github PK
View Code? Open in Web Editor NEWBase62 Encoding C# implementation
License: MIT License
Base62 Encoding C# implementation
License: MIT License
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);
> }
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.
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.
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);
}
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.