mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 08:49:38 +02:00
* Add TestStreamFormat
This commit is contained in:
parent
7506277dc1
commit
186f93a8c9
@ -2727,7 +2727,29 @@ begin
|
||||
Output.FixupResourceHeader(FixupInfo); // Insert real resource data size
|
||||
end;
|
||||
|
||||
function TestStreamFormat(const Stream: TStream): TStreamOriginalFormat;
|
||||
|
||||
const
|
||||
StartChars = [#9, #10, #13, #11, 'o', 'O','i','I',' '];
|
||||
|
||||
var
|
||||
aPos: Int64;
|
||||
Sig: Packed Array[0..3] of byte;
|
||||
IntSig : Longint absolute sig;
|
||||
|
||||
begin
|
||||
Result:=sofUnknown;
|
||||
aPos:=Stream.Position;
|
||||
IntSig:=0;
|
||||
Stream.Read(Sig,SizeOf(Sig));
|
||||
Stream.Seek(aPos,soBeginning);
|
||||
if (Sig[0]=$FF) or (IntSig=LongInt(FilerSignature)) or (IntSig=LongInt(FilerSignature1)) or (IntSig=0) then
|
||||
Result:=sofBinary
|
||||
else if (AnsiChar(Sig[0]) in StartChars) then
|
||||
Result:=sofText
|
||||
else if (Sig[1]=$BF) and (Sig[2]=$BB) and (Sig[3]=$EF) then
|
||||
Result:=sofUTF8Text;
|
||||
end;
|
||||
|
||||
{ Utility routines }
|
||||
|
||||
|
@ -2883,6 +2883,7 @@ procedure ObjectTextToBinary(Input, Output: TStream);
|
||||
|
||||
procedure ObjectResourceToText(Input, Output: TStream);
|
||||
procedure ObjectTextToResource(Input, Output: TStream);
|
||||
function TestStreamFormat(const Stream: TStream): TStreamOriginalFormat;
|
||||
|
||||
{ Utility routines }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user