Is there a simple method to match an array of bytes in an byte array?
<p>I'm trying to check for a sequence of bytes in a byte array. Is there a method in the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html" rel="nofollow noreferrer">ByteArray</a> <a href="http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d54.html" rel="nofollow noreferrer">class</a> that works like <code>indexOf()</code>? </p>

<p>For example, </p>

<p>I'm trying to find out if a file is a <a href="https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header" rel="nofollow noreferrer">PNG</a> or JPG and so I want to check the byte array for that sequence of characters. </p>

<pre><code>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") }
</code></pre>

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

<p>More info on the PNG Header array of hexadecimal characters <a href="https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header" rel="nofollow noreferrer">here</a>. </p>

<p><strong>Update:</strong><br>
I've just now thought that I wish I could use a RegEx to find what I'm looking for like this:  </p>

<pre><code>// dream code - find the value between those characters 
var data:Object = byteArray.exec(/89,50,4E,47(.*?)0xF0,0xF1/);
</code></pre>

<p>Of course, it is only a dream. It would be too easy if RegEx was supported in ByteArrays. </p>

<p>According to Nick's answer I need to: </p>

<blockquote>
  <p>...loop the byte array, grab each byte and if there's a match keep
  comparing until I either find the full match or the end of the file?</p>
</blockquote>

<p><em>Is there a method that does this part for me? That's what I'm wondering. It seems like something you'd have to do quite often so maybe there are functions. I can post what I've written so far if that's the case.</em> </p>