delagoya (owner)

Revisions

gist: 62072 Download_button fork
public
Public Clone URL: git://gist.github.com/62072.git
Embed All Files: show embed
MzXml.as #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package mz
{
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.utils.Dictionary;
public class MzXml
{
/**
* A random access parser for mzXML files.
*
*/
 
public var mz:Array;
public var mzi:Array;
 
private var f:File;
private var fs:FileStream;
private var fsize:int;
private var index:Dictionary; // [[id, offset, length] , [id, offset,length],...]
public function MzXml(file:File)
{
this.f = file;
this.fs = new FileStream();
 
// open the file to get the size
fs.open(this.f,FileMode.READ);
this.fsize = fs.bytesAvailable;
fs.close()
parseIndex();
}
 
private function parseIndex():void
{
this.index = new Dictionary;
// find index offset
fs.open(f,FileMode.READ);
fs.position = new Number(fsize - 1000);
 
var tmp:String = fs.readUTFBytes(fs.bytesAvailable);
//<indexOffset>33573953</indexOffset>
var result:Array = tmp.match(/<indexOffset>(\d+)<\/indexOffset>/);
var iof:Number = new Number(result[1]);
 
// OK, now read in the index
fs.position = iof;
tmp = fs.readUTFBytes(fs.bytesAvailable);
fs.close();
// make a valid XML string to use by matching only the index structure
var xml:XML = XML(tmp.match(/(<index>.+<\/index>)/m)[0]);
// iterate through the index to get the offsets
var i:int = 0;
for each (var offset:XML in xml.offset) {
index[i] = [offset.@id, new int(offset.toString()),null];
if (i > 0) {
index[i-1][2] = index[i][1] - index[i-1][1];
}
i += 1;
}
// fix the last index length
index [i][2] = iof - index[i][1];
}
}
}