What “padding” are you referring to? Each must be 2 characters. And there is a 
standard that covers this https://tools.ietf.org/html/rfc4648

> On Feb 2, 2021, at 10:57 AM, 'Axel Wagner' via golang-nuts 
> <golang-nuts@googlegroups.com> wrote:
> 
> 
> Rogers approach seems like the best one to me - wrap the input in a custom 
> `io.Reader` that transparently replaces `-_` with `+/` respectively (and drop 
> trailing `=`). The bufio approach doesn't work, because there is no guarantee 
> that one of the distinguishing characters is early in the stream and the 
> "send it to multiple decoders" approach duplicates effort and wastes 
> resources.
> 
>> On Tue, Feb 2, 2021 at 5:43 PM Amnon <amno...@gmail.com> wrote:
>> Reading through a bufio.Reader is often useful for these situations.
>> You can peek the beginning of the input in order to decide which decoder to 
>> use.
>> 
>> Another option is to use the io.TeeReader to duplicate the reader,
>> and then send one copy to each decoder.
>> One will succeed, and give you the output.
>> But you will need to drain the one that fails to prevent the TeeReader form 
>> stalling.
>> 
>> 
>>> On Tuesday, 2 February 2021 at 14:17:19 UTC axel.wa...@googlemail.com wrote:
>>> This question isn't about the decoded data, but about *which* base64 format 
>>> is used - i.e. if it uses padding or not and what 2 characters are used 
>>> outside of a-zA-Z0-9. The most common ones use +/ and -_, so it's easy to 
>>> tell which is used and just accept either (and padding can be viewed as 
>>> optional during decoding anyway).
>>> 
>>>> On Tue, Feb 2, 2021 at 2:37 PM Robert Engels <ren...@ix.netcom.com> wrote:
>>>> Base64 is always ASCII. The encoded data may be in an arbitrary format. 
>>>> You need to pass additional metadata or try and detect its encoding. 
>>>> 
>>>>>> On Feb 2, 2021, at 6:50 AM, roger peppe <rogp...@gmail.com> wrote:
>>>>>> 
>>>>> 
>>>>> In case you find it helpful, here's a clone of the base64 command that I 
>>>>> wrote in Go. I did it precisely because I wanted to be able to decode any 
>>>>> encoding scheme interchangeably.
>>>>> 
>>>>> https://github.com/rogpeppe/misc/blob/master/cmd/base64/base64.go
>>>>> 
>>>>> I agree that it might be useful to have some of this functionality 
>>>>> available in the standard library.
>>>>> 
>>>>>   cheers,
>>>>>     rog.
>>>>> 
>>>>>> On Tue, 2 Feb 2021 at 09:08, hey...@gmail.com <hey...@gmail.com> wrote:
>>>>>> Hi,
>>>>>> 
>>>>>> I have an io.Reader whose content is encoded in base64 with encoding 
>>>>>> type unknown. Since there shouldn't be any ambiguity between the two, is 
>>>>>> it possible to make the base64 automatically pick the right one to 
>>>>>> decode?
>>>>>> 
>>>>>> Currently I have to read everything out to pin down the encoding, which 
>>>>>> defeats the purpose of using an io.Reader.
>>>>>> 
>>>>>> Is there a solution to this problem?
>>>>>> 
>>>>>> Thanks in advance.
>>>>>> 
>>>>>> 
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "golang-nuts" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>>> an email to golang-nuts...@googlegroups.com.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/golang-nuts/0ccee37d-319e-41b3-9bfd-3dc46e0fad78n%40googlegroups.com.
>>>>> 
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "golang-nuts" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>>> email to golang-nuts...@googlegroups.com.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/golang-nuts/CAJhgacjkUUSr-dOPFU-W4vG_AXZRY_dYYe2ti-iPuu_XUL%2BNVw%40mail.gmail.com.
>>>> 
>>>> -- 
>>>> You received this message because you are subscribed to the Google Groups 
>>>> "golang-nuts" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>>> email to golang-nuts...@googlegroups.com.
>>> 
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/golang-nuts/CF76EF37-6F82-42FF-B4D6-4B9FC02F25FC%40ix.netcom.com.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/44621cb2-fae7-4f40-9e50-35b157f4e838n%40googlegroups.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGGkOX9HzF6e178Cu6BD9Hg4x5LT7AutHkUDPvyK%2BFmYg%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5B53EC9F-AF04-4041-9236-7463AD2676B4%40ix.netcom.com.

Reply via email to