Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first pass at synchronous backend

  • Loading branch information...
commit 1e5c7955285bf9cc272ac4336b21769cbcb82271 1 parent ba0af9d
Timothy J Fontaine authored March 06, 2011
196  examples/rrdContent.html
... ...
@@ -1,196 +0,0 @@
1  
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2  
-<!--
3  
- Example HTML/javascript file that display the
4  
- content of a RRD archive file
5  
- Part of the javascriptRRD package
6  
- Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu
7  
-
8  
- Original repository: http://javascriptrrd.sourceforge.net/
9  
- 
10  
- MIT License [http://www.opensource.org/licenses/mit-license.php]
11  
-
12  
--->
13  
-
14  
-<!--
15  
- This example will print out RRD content in integer format.
16  
- Make sure all RRD values can fit in an integer
17  
--->
18  
-
19  
-<html>
20  
-  
21  
-    <script type="text/javascript" src="../lib/binaryXHR.js"></script>
22  
-    <script type="text/javascript" src="../lib/rrdFile.js"></script>
23  
-  <head>
24  
-    <title>RRD Content</title>
25  
-  </head>
26  
-
27  
-  <body>
28  
-    <h1 id="title">RRD Raw Content</h1>
29  
-
30  
-    RRD URL:
31  
-    <input type="text" id="input_fname" value="example1.rrd"
32  
-           onchange="fname_update()">
33  
-     <button onclick="fname_update()">Update</button>
34  
-    <hr>
35  
-     <table border=0>
36  
-        <tr>
37  
-	  <td>DS: <select id="select_ds"></select></td>
38  
-	  <td>RRA: <select id="select_rra"></select></td>
39  
-	  <td>Columns: <select id="select_columns">
40  
-                          <option value="1"/>1</option>
41  
-                          <option value="2"/>2</option>
42  
-                          <option value="4"/>4</option>
43  
-                          <option value="5"/>5</option>
44  
-                          <option value="10"/>10</option>
45  
-                          <option value="20" selected/>20</option>
46  
-                       </select></td>
47  
-	  <td><button id="dsrra_button" onclick="element_update()" disabled=1>Update</button></td>
48  
-	</tr>
49  
-    </table>
50  
-   
51  
-    <hr>
52  
-
53  
-    <table id="infotable" border=1>
54  
-        <tr><td colspan="21"><b>Javascript needed for this page to work</b></td></tr>
55  
-	<tr><td><b>RRD file</b></td><td id="fname" colspan="20">None</td></tr>
56  
-	<tr>
57  
-	  <td><b>DS</b></td><td id="ds_el" colspan="9">None</td>
58  
-	  <td colspan="3"><b>RRA</b></td><td id="rra_el" colspan="8">None</td>
59  
-	</tr>
60  
-	<tr><th>Offset</th><th colspan="20">Data</th></tr>
61  
-    </table>
62  
-
63  
-    <script type="text/javascript">
64  
-      // Remove the Javascript warning
65  
-      document.getElementById("infotable").deleteRow(0);
66  
-
67  
-      // fname and rrd_data are the global variable used by all the functions below
68  
-      fname=document.getElementById("input_fname").value;
69  
-      rrd_data=undefined;
70  
-
71  
-      // This function updates the Web Page with the data from the RRD archive header
72  
-      // when a new file is selected
73  
-      function update_fname() {
74  
-        // Update DS info
75  
-        var nrDSs=rrd_data.getNrDSs()
76  
-
77  
-        // But first cleanup anything that may be there from before
78  
-        document.getElementById("ds_el").firstChild.data="None";
79  
-        var oSelect=document.getElementById("select_ds");
80  
-        while (oSelect.options.length>=1) {
81  
-          oSelect.remove(0);
82  
-        }         
83  
-
84  
-        for (var i=0; i<nrDSs; i++) {
85  
-          var ds_name=rrd_data.getDS(i).getName();
86  
-          oSelect.options.add(new Option(ds_name,i,false,false));
87  
-        }
88  
-
89  
-        // Update RRA info
90  
-        var nrRRAs=rrd_data.getNrRRAs()
91  
-
92  
-        // But first cleanup anything that may be there from before
93  
-        document.getElementById("rra_el").firstChild.data="None";
94  
-        var oSelect=document.getElementById("select_rra");
95  
-        while (oSelect.options.length>=1) {
96  
-          oSelect.remove(0);
97  
-        }         
98  
-
99  
-        for (var i=0; i<nrRRAs; i++) {
100  
-          oSelect.options.add(new Option(i,i,false,false));
101  
-        }
102  
-
103  
-        // cleanup
104  
-        // rows may have been added during previous updates
105  
-        var oTable=document.getElementById("infotable");
106  
-        while (oTable.rows.length>=4) {
107  
-          oTable.deleteRow(3);
108  
-        } 
109  
-
110  
-        // Finally, update the file name and enable the update button
111  
-        document.getElementById("fname").firstChild.data=fname;
112  
-        document.getElementById("dsrra_button").disabled=0;
113  
-      }
114  
-
115  
-      // This function updates the Web Page with the data from the RRD archive
116  
-      function element_update() {
117  
-        oSelDS=document.getElementById("select_ds");
118  
-        ds_idx=Math.round(oSelDS.options[oSelDS.selectedIndex].value);
119  
-        oSelRRA=document.getElementById("select_rra");
120  
-        rra_idx=oSelRRA.options[oSelRRA.selectedIndex].value;
121  
-        oSelClm=document.getElementById("select_columns");
122  
-        clm_nr=Math.round(oSelClm.options[oSelClm.selectedIndex].value);
123  
-
124  
-        // cleanup
125  
-        // rows may have been added during previous updates
126  
-        var oTable=document.getElementById("infotable");
127  
-        while (oTable.rows.length>=4) {
128  
-          oTable.deleteRow(3);
129  
-        } 
130  
-
131  
-        // Generic header info
132  
-        document.getElementById("ds_el").firstChild.data=rrd_data.getDS(ds_idx).getName();;
133  
-        document.getElementById("rra_el").firstChild.data=rra_idx;
134  
-
135  
-        // get RRA info
136  
-        var rra=rrd_data.getRRA(rra_idx);
137  
-        var rows=rra.getNrRows();
138  
-
139  
-        var oRow=undefined;
140  
-        for (var i=0; i<rows;i++) {
141  
-          if ((i%clm_nr)==0) {
142  
-            // One new row every clm_nr
143  
-            oRow=oTable.insertRow(-1);
144  
-            var oCell=oRow.insertCell(-1);
145  
-            oCell.innerHTML=i;
146  
-          }
147  
-          var oCell=oRow.insertCell(-1);
148  
-          oCell.colSpan=20/clm_nr;
149  
-          var el=rra.getElFast(i,ds_idx);
150  
-          if (el!=undefined) {
151  
-           oCell.innerHTML=Math.round(rra.getElFast(i,ds_idx));
152  
-          } else {
153  
-           oCell.innerHTML="-";
154  
-          }
155  
-        }
156  
-      }      
157  
-
158  
-      // This is the callback function that,
159  
-      // given a binary file object,
160  
-      // verifies that it is a valid RRD archive
161  
-      // and performs the update of the Web page
162  
-      function update_fname_handler(bf) {
163  
-          var i_rrd_data=undefined;
164  
-          try {
165  
-            var i_rrd_data=new RRDFile(bf);            
166  
-          } catch(err) {
167  
-            alert("File "+fname+" is not a valid RRD archive!");
168  
-          }
169  
-          if (i_rrd_data!=undefined) {
170  
-            rrd_data=i_rrd_data;
171  
-            update_fname()
172  
-          }
173  
-      }
174  
-
175  
-      // this function is invoked when the RRD file name changes
176  
-      function fname_update() {
177  
-        fname=document.getElementById("input_fname").value;
178  
-        try {
179  
-          FetchBinaryURLAsync(fname,update_fname_handler);
180  
-        } catch (err) {
181  
-           alert("Failed loading "+fname+"\n"+err);
182  
-        }
183  
-      }
184  
-
185  
-      // Uncomment this part if you want the Web page to load the
186  
-      // default RRD file at load time
187  
-      //
188  
-      //try {
189  
-      //  FetchBinaryURLAsync(fname,update_fname_handler);
190  
-      //} catch (err) {
191  
-      //  alert("Failed loading "+fname+"\n"+err);
192  
-      //}
193  
-      
194  
-    </script>
195  
-  </body>
196  
-</html>
34  examples/rrdContent.js
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ Example HTML/javascript file that display the
  3
+ content of a RRD archive file
  4
+ Part of the javascriptRRD package
  5
+ Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu
  6
+
  7
+ Original repository: http://javascriptrrd.sourceforge.net/
  8
+ 
  9
+ MIT License [http://www.opensource.org/licenses/mit-license.php]
  10
+*/
  11
+
  12
+/*
  13
+ This example will print out RRD content in integer format.
  14
+ Make sure all RRD values can fit in an integer
  15
+*/
  16
+var bf = require('../lib/binaryFile.js')
  17
+var rrf = require('../lib/rrdFile.js')
  18
+
  19
+console.log('RRD Raw Content')
  20
+var fname = 'example1.rrd'
  21
+
  22
+bf.FetchBinaryURLAsync(fname, function(binfile){
  23
+  var rrd_data = new rrf.RRDFile(binfile)
  24
+  var nrDSs=rrd_data.getNrDSs()
  25
+  
  26
+  for (var i=0; i<nrDSs; i++) {
  27
+    var ds=rrd_data.getDS(i)
  28
+    var rra=rrd_data.getRRA(i)
  29
+    console.log(ds.getName())
  30
+    for(var j=0; j<rra.getNrRows(); j++) {
  31
+      console.log(Math.round(rra.getElFast(j, i)))
  32
+    }
  33
+  }
  34
+})
136  examples/rrdHeaderInfo.html
... ...
@@ -1,136 +0,0 @@
1  
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2  
-<!--
3  
- Example HTML/javascript file that display the
4  
- header of a RRD archive files
5  
- Part of the javascriptRRD package
6  
- Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu
7  
-
8  
- Original repository: http://javascriptrrd.sourceforge.net/
9  
- 
10  
- MIT License [http://www.opensource.org/licenses/mit-license.php]
11  
-
12  
--->
13  
-
14  
-<html>
15  
-  
16  
-    <script type="text/javascript" src="../lib/binaryXHR.js"></script>
17  
-    <script type="text/javascript" src="../lib/rrdFile.js"></script>
18  
-  <head>
19  
-    <title>RRD Header Info</title>
20  
-  </head>
21  
-
22  
-  <body>
23  
-    <h1 id="title">RRD Header Info</h1>
24  
-
25  
-    RRD URL:
26  
-    <input type="text" id="input_fname" value="example1.rrd"
27  
-           onchange="input_update()">
28  
-     <button onclick="input_update()">Update</button>
29  
-    <hr>
30  
-
31  
-    <table id="infotable" border=1>
32  
-        <tr><td colspan="5"><b>Javascript needed for this page to work</b></td></tr>
33  
-	<tr><td><b>RRD file</b></td><td id="fname" colspan="4">None</td></tr>
34  
-	<tr><td><b>Min Step</b></td><td id="step" align="right">N/A</td><td><b>Last update</b></td><td id="last_update" colspan="2">N/A</td></tr>
35  
-    </table>
36  
-
37  
-    <script type="text/javascript">
38  
-      // Remove the Javascript warning
39  
-      document.getElementById("infotable").deleteRow(0);
40  
-
41  
-      // fname is the global variable used by all the functions below
42  
-      fname=document.getElementById("input_fname").value;
43  
-
44  
-      // This function updates the Web Page with the data from the RRD archive
45  
-      function update_info(fname,rrd_data) {
46  
-        // cleanup
47  
-        // rows may have been added during previous updates
48  
-        var oTable=document.getElementById("infotable");
49  
-        while (oTable.rows.length>=3) {
50  
-          oTable.deleteRow(2);
51  
-        } 
52  
-
53  
-        // Generic header info
54  
-        document.getElementById("fname").firstChild.data=fname;
55  
-        document.getElementById("step").firstChild.data=rrd_data.getMinStep();
56  
-        document.getElementById("last_update").firstChild.data=rrd_data.getLastUpdate();
57  
-
58  
-        // DS info
59  
-        var nrDSs=rrd_data.getNrDSs()
60  
-        var oRow=oTable.insertRow(-1);
61  
-        var oCell=oRow.insertCell(0);
62  
-        oCell.innerHTML="<b>DS list</b>";
63  
-        oCell.colSpan=5;
64  
-        for (var i=0; i<nrDSs; i++) {
65  
-          var oDS=rrd_data.getDS(i);
66  
-          oRow=oTable.insertRow(-1);
67  
-          oCell=oRow.insertCell(0)
68  
-          oCell.innerHTML="<b>"+oDS.getName()+"</b>";
69  
-          oCell=oRow.insertCell(1)
70  
-          oCell.innerHTML=oDS.getType();
71  
-          oCell.colSpan=4;
72  
-        }
73  
-
74  
-        // RRA Info
75  
-        var nrRRAs=rrd_data.getNrRRAs()
76  
-        oRow=oTable.insertRow(-1);
77  
-        oCell=oRow.insertCell(0);
78  
-        oCell.innerHTML="<b>RRA list</b>";
79  
-        oCell.colSpan=5;
80  
-        for (var i=0; i<nrRRAs; i++) {
81  
-          var oRRA=rrd_data.getRRAInfo(i);
82  
-          oRow=oTable.insertRow(-1);
83  
-          oCell=oRow.insertCell(0)
84  
-          oCell.innerHTML=i;
85  
-          oCell.align="center";
86  
-          oCell=oRow.insertCell(1)
87  
-          oCell.innerHTML="<b>Rows</b>";
88  
-          oCell=oRow.insertCell(2)
89  
-          oCell.innerHTML=oRRA.getNrRows();
90  
-          oCell.align="right";
91  
-          oCell=oRow.insertCell(3)
92  
-          oCell.innerHTML="<b>Step</b>";
93  
-          oCell=oRow.insertCell(4)
94  
-          oCell.innerHTML=oRRA.getStep();
95  
-          oCell.align="right";
96  
-        }
97  
-      }      
98  
-
99  
-      // This is the callback function that,
100  
-      // given a binary file object,
101  
-      // verifies that it is a valid RRD archive
102  
-      // and performs the update of the Web page
103  
-      function update_info_handler(bf) {
104  
-          var rrd_data=undefined;
105  
-          try {
106  
-            var rrd_data=new RRDFile(bf);            
107  
-          } catch(err) {
108  
-            alert("File "+fname+" is not a valid RRD archive!");
109  
-          }
110  
-          if (rrd_data!=undefined) {
111  
-            update_info(fname,rrd_data)
112  
-          }
113  
-      }
114  
-
115  
-      // this function is invoked when the RRD file name changes
116  
-      function input_update() {
117  
-        fname=document.getElementById("input_fname").value;
118  
-        try {
119  
-          FetchBinaryURLAsync(fname,update_info_handler);
120  
-        } catch (err) {
121  
-           alert("Failed loading "+fname+"\n"+err);
122  
-        }
123  
-      }
124  
-
125  
-      // Uncomment this part if you want the Web page to load the
126  
-      // default RRD file at load time
127  
-      //
128  
-      //try {
129  
-      //  FetchBinaryURLAsync(fname,update_info_handler);
130  
-      //} catch (err) {
131  
-      //  alert("Failed loading "+fname+"\n"+err);
132  
-      //}
133  
-      
134  
-    </script>
135  
-  </body>
136  
-</html>
35  examples/rrdHeaderInfo.js
... ...
@@ -0,0 +1,35 @@
  1
+/*
  2
+Example HTML/javascript file that display the
  3
+content of a RRD archive file
  4
+Part of the javascriptRRD package
  5
+Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu
  6
+
  7
+Original repository: http://javascriptrrd.sourceforge.net/
  8
+
  9
+MIT License [http://www.opensource.org/licenses/mit-license.php]
  10
+*/
  11
+
  12
+var bf = require('../lib/binaryFile.js')
  13
+var rrf = require('../lib/rrdFile.js')
  14
+
  15
+console.log('RRD Header Info')
  16
+
  17
+var fname = 'example1.rrd'
  18
+bf.FetchBinaryURLAsync(fname, function(binfile, blarg) {
  19
+  var rrdfile = new rrf.RRDFile(binfile)
  20
+
  21
+  console.log('Min Step', rrdfile.getMinStep())
  22
+  console.log('Last update', new Date(rrdfile.getLastUpdate() * 1000))
  23
+
  24
+  console.log('DS ---')
  25
+  for(var i=0; i < rrdfile.getNrDSs(); i++) {
  26
+    var ds = rrdfile.getDS(i);
  27
+    console.log(ds.getName(), ds.getType());
  28
+  }
  29
+
  30
+  console.log('RRAs ---')
  31
+  for(var i=0; i < rrdfile.getNrRRAs(); i++) {
  32
+    var rra = rrdfile.getRRAInfo(i)
  33
+    console.log('rows', rra.getNrRows(), 'step', rra.getStep())
  34
+  }  
  35
+})
144  lib/binaryXHR.js → lib/binaryFile.js
@@ -13,6 +13,8 @@
13 13
  *   MIT License [http://www.opensource.org/licenses/mit-license.php]
14 14
  */
15 15
 
  16
+var fs = require('fs')
  17
+
16 18
 // ============================================================
17 19
 // Exception class
18 20
 function InvalidBinaryFile(msg) {
@@ -37,24 +39,20 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
37 39
 	var doubleMantExpLo=Math.pow(2,-52);
38 40
 	var doubleMantExpFast=Math.pow(2,-20);
39 41
 
40  
-	this.getRawData = function() {
41  
-		return data;
42  
-	}
43  
-
44  
-	if (typeof strData == "string") {
45  
-		dataLength = iDataLength || data.length;
  42
+  var fsstats = fs.fstatSync(data)
  43
+  dataLength = fsstats.size
  44
+  
  45
+  var buff = new Buffer(512)
46 46
 
47  
-		this.getByteAt = function(iOffset) {
48  
-			return data.charCodeAt(iOffset + dataOffset) & 0xFF;
49  
-		}
50  
-	} else if (typeof strData == "unknown") {
51  
-		dataLength = iDataLength || IEBinary_getLength(data);
  47
+	/*this.getRawData = function() {
  48
+	  var buff = new Buffer(dataLength);
  49
+		var bytes = fs.readSync(data, buff, 0, dataLength);
  50
+		return buff;
  51
+	}*/
52 52
 
53  
-		this.getByteAt = function(iOffset) {
54  
-			return IEBinary_getByteAt(data, iOffset + dataOffset);
55  
-		}
56  
-	} else {
57  
-	  throw new InvalidBinaryFile("Unsupported type " + (typeof strData));
  53
+	this.getByteAt = function(iOffset) {
  54
+	  var bytes = fs.readSync(data, buff, 0, 1, iOffset + dataOffset)
  55
+		return buff[0];
58 56
 	}
59 57
 
60 58
 	this.getLength = function() {
@@ -74,6 +72,7 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
74 72
 		if (iShort < 0) iShort += 65536;
75 73
 		return iShort;
76 74
 	}
  75
+	
77 76
 	this.getSShortAt = function(iOffset) {
78 77
 		var iUShort = this.getShortAt(iOffset);
79 78
 		if (iUShort > 32767)
@@ -81,16 +80,15 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
81 80
 		else
82 81
 			return iUShort;
83 82
 	}
  83
+	
84 84
 	this.getLongAt = function(iOffset) {
85  
-		var iByte1 = this.getByteAt(iOffset),
86  
-			iByte2 = this.getByteAt(iOffset + 1),
87  
-			iByte3 = this.getByteAt(iOffset + 2),
88  
-			iByte4 = this.getByteAt(iOffset + 3);
  85
+	  var bytes = fs.readSync(data, buff, 0, 4, iOffset)
89 86
 
90  
-		var iLong = (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1;
  87
+		var iLong = (((((buff[3] << 8) + buff[2]) << 8) + buff[1]) << 8) + buff[0];
91 88
 		if (iLong < 0) iLong += 4294967296;
92 89
 		return iLong;
93 90
 	}
  91
+	
94 92
 	this.getSLongAt = function(iOffset) {
95 93
 		var iULong = this.getLongAt(iOffset);
96 94
 		if (iULong > 2147483647)
@@ -98,37 +96,42 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
98 96
 		else
99 97
 			return iULong;
100 98
 	}
  99
+	
101 100
 	this.getStringAt = function(iOffset, iLength) {
102  
-		var aStr = [];
103  
-		for (var i=iOffset,j=0;i<iOffset+iLength;i++,j++) {
104  
-			aStr[j] = String.fromCharCode(this.getByteAt(i));
105  
-		}
106  
-		return aStr.join("");
  101
+		var bytes = fs.readSync(data, buff, iOffset, iLength, 0)
  102
+		return buff.toString('ascii', 0, bytes)
107 103
 	}
108 104
 
109 105
 	// Added
110 106
 	this.getCStringAt = function(iOffset, iMaxLength) {
111  
-		var aStr = [];
  107
+	  
  108
+	  /*var aStr = [];
112 109
 		for (var i=iOffset,j=0;(i<iOffset+iMaxLength) && (this.getByteAt(i)>0);i++,j++) {
113 110
 			aStr[j] = String.fromCharCode(this.getByteAt(i));
114 111
 		}
115  
-		return aStr.join("");
  112
+		return aStr.join("");*/
  113
+
  114
+	  var bytes = fs.readSync(data, buff, 0, iMaxLength, iOffset)
  115
+	  
  116
+	  for(var i=0; i < bytes; i++) {
  117
+	    var b = buff.toString('ascii', i, i+1)
  118
+	    if(b == '\0') {
  119
+	      var ret = buff.toString('ascii', 0, i)
  120
+	      return ret
  121
+	    }
  122
+	  }
  123
+	  
  124
+	  return buff.toString('ascii', 0, bytes)
116 125
 	}
117 126
 
118 127
 	// Added
119 128
 	this.getDoubleAt = function(iOffset) {
120  
-		var iByte1 = this.getByteAt(iOffset),
121  
-			iByte2 = this.getByteAt(iOffset + 1),
122  
-			iByte3 = this.getByteAt(iOffset + 2),
123  
-		        iByte4 = this.getByteAt(iOffset + 3),
124  
-		        iByte5 = this.getByteAt(iOffset + 4),
125  
-			iByte6 = this.getByteAt(iOffset + 5),
126  
-			iByte7 = this.getByteAt(iOffset + 6),
127  
-			iByte8 = this.getByteAt(iOffset + 7);
128  
-		var iSign=iByte8 >> 7;
129  
-		var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4);
130  
-		var iMantHi=((((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5) << 8) + iByte4;
131  
-		var iMantLo=((((iByte3) << 8) + iByte2) << 8) + iByte1;
  129
+		var bytes = fs.readSync(data, buff, 0, 8, iOffset)
  130
+		
  131
+		var iSign=buff[7] >> 7;
  132
+		var iExpRaw=((buff[7] & 0x7F)<< 4) + (buff[6] >> 4);
  133
+		var iMantHi=((((((buff[6] & 0x0F) << 8) + buff[5]) << 8) + buff[4]) << 8) + buff[3];
  134
+		var iMantLo=((((buff[2]) << 8) + buff[1]) << 8) + buff[0];
132 135
 
133 136
 		if (iExpRaw==0) return 0.0;
134 137
 		if (iExpRaw==0x7ff) return undefined;
@@ -164,38 +167,11 @@ function BinaryFile(strData, iDataOffset, iDataLength) {
164 167
 }
165 168
 
166 169
 
167  
-document.write(
168  
-	"<script type='text/vbscript'>\r\n"
169  
-	+ "Function IEBinary_getByteAt(strBinary, iOffset)\r\n"
170  
-	+ "	IEBinary_getByteAt = AscB(MidB(strBinary,iOffset+1,1))\r\n"
171  
-	+ "End Function\r\n"
172  
-	+ "Function IEBinary_getLength(strBinary)\r\n"
173  
-	+ "	IEBinary_getLength = LenB(strBinary)\r\n"
174  
-	+ "End Function\r\n"
175  
-	+ "</script>\r\n"
176  
-);
177  
-
178  
-
179  
-
180 170
 // ===============================================================
181 171
 // Load a binary file from the specified URL 
182 172
 // Will return an object of type BinaryFile
183 173
 function FetchBinaryURL(url) {
184  
-  var request =  new XMLHttpRequest();
185  
-  request.open("GET", url,false);
186  
-  try {
187  
-    request.overrideMimeType('text/plain; charset=x-user-defined');
188  
-  } catch (err) {
189  
-    // ignore any error, just to make both FF and IE work
190  
-  }
191  
-  request.send(null);
192  
-
193  
-  var response=request.responseBody;
194  
-  if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE
195  
-    response=request.responseText;
196  
-  }
197  
-  var bf=new BinaryFile(response);
198  
-  return bf;
  174
+  return new BinaryFile(fs.openSync(url, 'r'));
199 175
 }
200 176
 
201 177
 
@@ -206,29 +182,11 @@ function FetchBinaryURL(url) {
206 182
 //  - bf = an object of type BinaryFile
207 183
 //  - optional argument object (used only if callback_arg not undefined) 
208 184
 function FetchBinaryURLAsync(url, callback, callback_arg) {
209  
-  var callback_wrapper = function() {
210  
-    if(this.readyState == 4) {
211  
-      var response=this.responseBody;
212  
-      if (response==undefined){ // responseBody is non standard, but the only way to make it work in IE
213  
-	response=this.responseText;
214  
-      }
215  
-      var bf=new BinaryFile(response);
216  
-      if (callback_arg!=null) {
217  
-	callback(bf,callback_arg);
218  
-      } else {
219  
-	callback(bf);
220  
-      }
221  
-    }
222  
-  }
223  
-
224  
-  var request =  new XMLHttpRequest();
225  
-  request.onreadystatechange = callback_wrapper;
226  
-  request.open("GET", url,true);
227  
-  try {
228  
-    request.overrideMimeType('text/plain; charset=x-user-defined');
229  
-  } catch (err) {
230  
-    // ignore any error, just to make both FF and IE work
231  
-  }
232  
-  request.send(null);
233  
-  return request
  185
+  fs.open(url, 'r', function(err, fd) {
  186
+    callback(new BinaryFile(fd), callback_arg)
  187
+  });
234 188
 }
  189
+
  190
+exports.BinaryFile = BinaryFile;
  191
+exports.FetchBinaryURL = FetchBinaryURL;
  192
+exports.FetchBinaryURLAsync = FetchBinaryURLAsync;
10  lib/rrdFile.js
@@ -63,7 +63,7 @@ InvalidRRD.prototype.toString = function() {
63 63
 
64 64
 // ============================================================
65 65
 // RRD DS Info class
66  
-function RRDDS(rrd_data,rrd_data_idx,my_idx) {
  66
+var RRDDS = exports.RRDDS = function (rrd_data,rrd_data_idx,my_idx) {
67 67
   this.rrd_data=rrd_data;
68 68
   this.rrd_data_idx=rrd_data_idx;
69 69
   this.my_idx=my_idx;
@@ -88,7 +88,7 @@ RRDDS.prototype.getMax = function() {
88 88
 
89 89
 // ============================================================
90 90
 // RRD RRA Info class
91  
-function RRDRRAInfo(rrd_data,rra_def_idx,
  91
+var RRDRRAInfo = exports.RRDRRAInfo = function (rrd_data,rra_def_idx,
92 92
 		    rrd_align,row_cnt,pdp_step,my_idx) {
93 93
   this.rrd_data=rrd_data;
94 94
   this.rra_def_idx=rra_def_idx;
@@ -129,7 +129,7 @@ RRDRRAInfo.prototype.getCFName = function() {
129 129
 
130 130
 // ============================================================
131 131
 // RRD RRA handling class
132  
-function RRDRRA(rrd_data,rra_ptr_idx,
  132
+var RRDRRA = exports.RRDRRA = function (rrd_data,rra_ptr_idx,
133 133
 		rra_info,
134 134
 		header_size,prev_row_cnts,ds_cnt) {
135 135
   this.rrd_data=rrd_data;
@@ -196,7 +196,7 @@ RRDRRA.prototype.getElFast = function(row_idx,ds_idx) {
196 196
 
197 197
 // ============================================================
198 198
 // RRD Header handling class
199  
-function RRDHeader(rrd_data) {
  199
+var RRDHeader = exports.RRDHeader = function (rrd_data) {
200 200
   this.rrd_data=rrd_data;
201 201
   this.validate_rrd();
202 202
   this.load_header();
@@ -357,7 +357,7 @@ RRDHeader.prototype.getRRAInfo = function(idx) {
357 357
 // 
358 358
 // Arguments:
359 359
 //   bf must be an object compatible with the BinaryFile interface
360  
-function RRDFile(bf) {
  360
+var RRDFile = exports.RRDFile = function (bf) {
361 361
   var rrd_data=bf
362 362
 
363 363
   this.rrd_header=new RRDHeader(rrd_data);

0 notes on commit 1e5c795

Please sign in to comment.
Something went wrong with that request. Please try again.