Delphi的Base64转流 及 流转Base64的方法
- //Base64码转流
- procedure Base64ToStream(const ABase64: WideString;
- AStream: TStream);
- var
- objSS: TStringStream;
- s: string;
- begin
- if ABase64 = '' then Exit;
- objSS := TStringStream.Create(ABase64);
- try
- DecodeStream(objSS, AStream);
- AStream.Position := 0;
- finally
- FreeAndNil(objSS);
- end;
- end;
- //流转Base64
- procedure StreamToBase64(AStream: TStream;
- var ABase64: WideString);
- var
- objSS: TStringStream;
- begin
- objSS := TStringStream.Create('');
- try
- EncodeStream(AStream, objSS);
- ABase64 := objSS.DataString;
- finally
- FreeAndNil(objSS);
- end;
- end;
复制代码