Long story, but I need to validate that a file is indeed a PNG.
I’ve tried several different permutations, but the signature check always fails. I tried the signature both as a plain string and as a memory block. I think the issue might with the encoding with which the BinaryStream.read method string is returned, but I’m kind of guessing there.
Any hints ?
validatePNG( filename as string ) as string
// dim signature as string = chr(&h89) + “PNG” + chr( &h0d ) + chr( &h0a ) + chr( &h1a ) + chr( &h0a )
dim signature as new MemoryBlock(8)
signature.Byte(0) = &h89
dim f as FolderItem = new FolderItem(filename)
if f <> nil and f.Exists then
dim readstream as BinaryStream
readstream = BinaryStream.Open(f)
dim buffer as string = readstream.Read(8, Encodings.ASCII)
if buffer.Mid(1,8) <> signature.mid(1,8) then // <— The strings never match
catch e as IOException