|
@@ -36,7 +36,6 @@ type
|
|
|
Buf: array[0..2] of Byte;
|
|
|
BufSize: Integer; // # of bytes used in Buf
|
|
|
public
|
|
|
- constructor Create(ASource: TStream);
|
|
|
destructor Destroy; override;
|
|
|
Function Flush : Boolean;
|
|
|
function Write(const Buffer; Count: Longint): Longint; override;
|
|
@@ -88,7 +87,7 @@ type
|
|
|
end;
|
|
|
|
|
|
function EncodeStringBase64(const s:string):String;
|
|
|
-function DecodeStringBase64(const s:string):String;
|
|
|
+function DecodeStringBase64(const s:string;strict:boolean=false):String;
|
|
|
|
|
|
implementation
|
|
|
|
|
@@ -127,11 +126,6 @@ const
|
|
|
|
|
|
Alphabet = ['a'..'z','A'..'Z','0'..'9','+','/','=']; // all 65 chars that are in the base64 encoding alphabet
|
|
|
|
|
|
-constructor TBase64EncodingStream.Create(ASource: TStream);
|
|
|
-begin
|
|
|
- inherited Create(ASource);
|
|
|
-end;
|
|
|
-
|
|
|
function TBase64EncodingStream.Flush : Boolean;
|
|
|
|
|
|
var
|
|
@@ -423,7 +417,7 @@ begin
|
|
|
raise EStreamError.Create('Invalid stream operation');
|
|
|
end;
|
|
|
|
|
|
-function DecodeStringBase64(const s:string):String;
|
|
|
+function DecodeStringBase64(const s:string;strict:boolean=false):String;
|
|
|
|
|
|
var
|
|
|
Instream,
|
|
@@ -434,11 +428,13 @@ begin
|
|
|
try
|
|
|
Outstream:=TStringStream.Create('');
|
|
|
try
|
|
|
- Decoder:=TBase64DecodingStream.Create(Instream,bdmMIME);
|
|
|
+ if strict then
|
|
|
+ Decoder:=TBase64DecodingStream.Create(Instream,bdmStrict)
|
|
|
+ else
|
|
|
+ Decoder:=TBase64DecodingStream.Create(Instream,bdmMIME);
|
|
|
try
|
|
|
Outstream.CopyFrom(Decoder,Decoder.Size);
|
|
|
- Outstream.Position:=0;
|
|
|
- Result:=Outstream.ReadString(Outstream.Size);
|
|
|
+ Result:=Outstream.DataString;
|
|
|
finally
|
|
|
Decoder.Free;
|
|
|
end;
|
|
@@ -464,8 +460,7 @@ begin
|
|
|
finally
|
|
|
Encoder.Free;
|
|
|
end;
|
|
|
- Outstream.Position:=0;
|
|
|
- Result:=Outstream.ReadString(Outstream.Size);
|
|
|
+ Result:=Outstream.DataString;
|
|
|
finally
|
|
|
Outstream.free;
|
|
|
end;
|