飘云 发表于 2014-2-5 00:36:14

Delphi 字节流 Base64编码

unit EncodingUtil;

interface

uses
SysUtils, Classes, Types, EncdDecd;

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

implementation

function BytesToBase64(const bytes : TByteDynArray) : string;
var
memoryStream : TMemoryStream;
begin
memoryStream := TMemoryStream.Create;
memoryStream.WriteBuffer(bytes, 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;

end.


EncdDecd单元:

//对流的编解码:
procedure EncodeStream(Input, Output: TStream); // 编码
procedure DecodeStream(Input, Output: TStream); // 解码

// 对字符串的编解码:
function EncodeString(const Input: string): string; // 编码
function DecodeString(const Input: string): string; // 解码


这几个函数在帮助中没有~~ 非公开
页: [1]
查看完整版本: Delphi 字节流 Base64编码