renmengye/base62-csharp

Extra 0 byte sometimes added on decode FromBase62()

Closed this issue · 2 comments

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);
>                                       }

Fixed in commit 7d1a764.

Thank you!