function MemoryBufferType( cBuf )
local cType, n, a
local cPunct := Chr( 9 ) + Chr( 10 ) + Chr( 12 ) + Chr( 13 ) + Chr( 26 ) + Chr( 141 )
local lExact := Set( _SET_EXACT, .f. )
local lBinary := .f.
local aTypes := { ;
{ "IMG.BMP", "BM", .t. }, ;
{ "IMG.PNG", Chr( 0x89 ) + "PNG", .f. }, ;
{ "IMG.ICO", Chr( 0 ) + Chr( 0 ) + Chr( 1 ), .f. }, ;
{ "IMG.JPG", Chr( 255 ) + Chr( 216 ) + Chr( 255 ), .f. }, ;
{ "IMG.GIF", "GIF8", .t. }, ;
{ "IMG.TIF", Chr(73) + Chr(73) + Chr(42), .t. }, ;
{ "IMG.TIF", Chr(77) + Chr(77) + Chr(42), .t. }, ;
{ "IMG.EMF", Chr( 1 ) + Chr( 0 ) + Chr( 0 ) + Chr( 0 ), .f., }, ;
{ "IMG.WMF", HEXTOSTR( "D7CDC69A00" ), .f. }, ;
{ "DOC.XML", "<?xml ", .f. }, ;
{ "DOC.RTF", "{\rtf", .f. }, ;
{ "DOC.GTF", "GTF" + Chr( 5 ), .f. }, ;
{ "DOC.PDF", "%PDF-", .f. }, ;
{ "DOC.DOC", HEXTOSTR( "D0CF11E0A1B11AE1" ), .f. }, ;
{ "DOC.DCX", HEXTOSTR( "504B030414" ), .f. } }
for each a in aTypes
if cBuf = a[ 2 ]
if a[ 3 ]
if IsBinaryData( SubStr( cBuf, 3, 15 ) )
cType := a[ 1 ]
endif
else
cType := a[ 1 ]
endif
EXIT
endif
next
Set( _SET_EXACT, lExact )
if ! Empty( cType )
return cType
endif
lBinary := IsBinaryData( cBuf )
if lBinary
if FreeImageIsLoaded() .and. ( n := IfNil( FITypeFromMemory( cBuf ), -1 ) ) >= 0
return "IMG." + cValToChar( n )
endif
cType := "BIN.HEX"
else
if IsUTF8( cBuf )
return "TXT.UTF8"
else
cType := "TXT.ANSI"
endif
endif
return cType