Hi,

I have tried to get base64 encoding to work for me but still have trouble doing this. I will need to be able to convert binary files to base 64 strings and then convert them back to binary files. However, at this point I am only trying to encode a file to base64 and then decode it to test out base64 unit.

I have tried different variations of the code below. The "decoded" file is the same size as the original, but something goes wrong because I am using a simple .wave file for testing and the "decoded" file does not play which indicate a problem.



begin
memFile := TMemoryStream.Create;
memEncoded := TMemoryStream.create;
memDecoded := tMemoryStream.Create;

memFile.LoadFromFile(extractfilepath(paramstr(0)) + 'Fail.wav');

Enc := TBase64EncodingStream.Create(memEncoded);

while (not IsEnd) do
   try
   Enc.WriteByte(memFile.ReadByte);
   except
      on e: EStreamError do IsEnd := true;
      end;

memEncoded.Position := 0;

Dec := TBase64DecodingStream.Create(memEncoded);

IsEnd := false;
While (Not IsEnd) do
   try
   memDecoded.WriteByte(Dec.ReadByte);
   except on e: EStreamError do IsEnd := true;
      end;

memDecoded.SaveToFile(extractfilepath(paramstr(0)) + 'decoded.wav');




--

Warm Regards,

Lee

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to