现在的位置: 首页 > 综合 > 正文

webservices 字节数组 Base64编码

2012年10月16日 ⁄ 综合 ⁄ 共 664字 ⁄ 字号 评论关闭

unit EncodingUtil;

interface

uses
SysUtils, Classes, Types, EncdDecd;

function BytesToBase64(const bytes : TByteArray) : string;
function StreamToBase64(AStream: TStream) : string;

implementation

function BytesToBase64(const bytes : TByteArray) : string;
var
memoryStream : TMemoryStream;
begin
memoryStream := TMemoryStream.Create;
memoryStream.WriteBuffer(bytes[0], Length(bytes));
memoryStream.Seek(0, soFromBeginning);
Result := StreamToBase64(memoryStream);
memoryStream.Free;
end;

function StreamToBase64(AStream: TStream) : string;
var
objSS: TStringStream;
begin
objSS := TStringStream.Create('');
try
EncodeStream(AStream, objSS); //Delphi7 自带unit EncdDecd的方法
Result := objSS.DataString;
finally
FreeAndNil(objSS);
end;
end;

抱歉!评论已关闭.