Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jul : base64 corrupt

www.cryer.info
Managed Newsgroup Archive

base64 corrupt

Subject:base64 corrupt
Posted by:"Marshall Fryman" (marshall.fryman_at_gmail.com)
Date:Tue, 22 Jul 2008 11:47:42

hello,

I've retrieved a base64 encoded string (supposed to be an image) using Indy
from an HTTPS Post and am now trying to decode the string back to a binary
file. I found an older reference from Remy that basically provided the
following code:

procedure TForm1.Base64ToBinary(var base64: widestring; const filename:
string);
var
    SS: TStringStream;
    MS: TMemoryStream;
    Decoder: TIdDecoderMIME;
begin
    SS := TStringStream.Create(base64);
    try
        MS := TMemoryStream.Create;
        try
            Decoder := TIdDecoderMIME.Create;
            try
                Decoder.DecodeBegin(MS);
                try
                    Decoder.Decode(SS);
//                      SZDecodeBase64(SS,MS);
                finally
                    Decoder.DecodeEnd;
                end;
            finally
                FreeAndNil(Decoder);
            end;
        finally
            MS.SaveToFile(filename);
            FreeAndNil(MS);
        end;
    finally
        FreeAndNil(SS);
    end;
end;

The problem is that the output is not 100% correct. There are semi-random
sections that match the correct output but not all. If I use SZCodeBaseX it
works fine so I know the base64 string is correct (I also used a straight
conversion tool to make sure it wasn't a bug in SZCodeBaseX that somehow
produced the correct output). Is TIdDecoderMime not supposed to convert any
generic base64 encoded string back to it's original form?

BTW, this is an indy 10 snapshot from a few months ago compiled with D2007.

thanks in advance,
m

Replies:

www.cryer.info
Managed Newsgroup Archive