vendredi 23 décembre 2016

Is there a simple method to match an array of bytes in an byte array?

I'm trying to check for a sequence of bytes in a byte array. Is there a method in the ByteArray class that works like indexOf()?

For example,

I'm trying to find out if a file is a PNG or JPG and so I want to check the byte array for that sequence of characters.

var PNG_INFO:Array = [89,50,4E,47];
var byteArray:ByteArray = new ByteArray();

var position:int = byteArray.indexOf(PNG_INFO);
var value:String = byteArray.readBytes(position, PNG_INFO.length);

if (value =="PNG") { trace("is png") }

I don't know if the code above is correct but I keep running into this problem where I have to find an array of bytes in a byte array. So my question is is there a method for what I'm looking for?

Aucun commentaire:

Enregistrer un commentaire