bireader 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/package.json +1 -1
- package/src/reader.js +14 -2
- package/src/writer.js +17 -0
package/README.md
CHANGED
|
@@ -173,6 +173,16 @@ Common functions for setup and movement shared by both (unless indicated).
|
|
|
173
173
|
<tr>
|
|
174
174
|
<td>Aliases</td>
|
|
175
175
|
<td>clip(startOffset, endOffset)<br>truncate(startOffset, endOffset)<br>slice(startOffset, endOffset)</td>
|
|
176
|
+
</tr>
|
|
177
|
+
<tr>
|
|
178
|
+
<td>Name</td>
|
|
179
|
+
<td>extract(<b>length</b>)</td>
|
|
180
|
+
<td align="center" rowspan="2">length of data from current position</td>
|
|
181
|
+
<td rowspan="2">Returns data from current read position to supplied length. <br><b>Note:</b> Does not affect supplied data or current read position.</td>
|
|
182
|
+
</tr>
|
|
183
|
+
<tr>
|
|
184
|
+
<td>Aliases</td>
|
|
185
|
+
<td>wrap(<b>length</b>)<br>lift(<b>length</b>)</td>
|
|
176
186
|
</tr>
|
|
177
187
|
<tr>
|
|
178
188
|
<td>Name</td>
|
package/package.json
CHANGED
package/src/reader.js
CHANGED
|
@@ -148,6 +148,18 @@ class bireader {
|
|
|
148
148
|
clip = this.crop = this.truncate = this.slice = function(startOffset, endOffset){
|
|
149
149
|
return this.data.slice(startOffset || 0, endOffset || this.offset)
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Extract array from current position to length supplied
|
|
154
|
+
* Note: Does not affect supplied data
|
|
155
|
+
* @param {number} length - length of data to copy from current offset
|
|
156
|
+
*/
|
|
157
|
+
extract = this.wrap = this.lift = function(length){
|
|
158
|
+
if(this.offset + (length ||0) > this.size){
|
|
159
|
+
throw new Error("End offset outside of data: " + this.size)
|
|
160
|
+
}
|
|
161
|
+
return this.data.slice(this.offset, this.offset + (length ||0))
|
|
162
|
+
}
|
|
151
163
|
|
|
152
164
|
/**
|
|
153
165
|
* Returns current data
|
|
@@ -2647,9 +2659,9 @@ class bireader {
|
|
|
2647
2659
|
this.#check_size(4)
|
|
2648
2660
|
var read;
|
|
2649
2661
|
if((endian != undefined ? endian : this.endian) == "little"){
|
|
2650
|
-
read = ((
|
|
2662
|
+
read = (((this.data[this.offset + 3] & 0xFF)<< 24) | ((this.data[this.offset + 2] & 0xFF) << 16) | ((this.data[this.offset + 1] & 0xFF) << 8) | (this.data[this.offset] & 0xFF))
|
|
2651
2663
|
} else {
|
|
2652
|
-
read = (
|
|
2664
|
+
read = ((this.data[this.offset] & 0xFF) << 24) | ((this.data[this.offset + 1] & 0xFF) << 16) | ((this.data[this.offset + 2] & 0xFF) << 8) | (this.data[this.offset + 3] & 0xFF)
|
|
2653
2665
|
}
|
|
2654
2666
|
this.offset += 4
|
|
2655
2667
|
if(unsigned == undefined || unsigned == false){
|
package/src/writer.js
CHANGED
|
@@ -213,6 +213,23 @@ class biwriter {
|
|
|
213
213
|
}
|
|
214
214
|
return this.data.slice(Math.abs(startOffset || 0), endOffset || this.offset)
|
|
215
215
|
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Extract array from current position to length supplied
|
|
219
|
+
* Note: Does not affect supplied data
|
|
220
|
+
* Note: Will extend array if strict mode is off
|
|
221
|
+
* @param {number} length - length of data to copy from current offset
|
|
222
|
+
*/
|
|
223
|
+
extract = this.wrap = this.lift = function(length){
|
|
224
|
+
if(this.offset + (length ||0) > this.size){
|
|
225
|
+
if(this.strict == false){
|
|
226
|
+
this.extendArray(this.offset + (length ||0) - this.size)
|
|
227
|
+
} else {
|
|
228
|
+
throw new Error("End offset outside of data: " + this.size)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return this.data.slice(this.offset, this.offset + (length ||0))
|
|
232
|
+
}
|
|
216
233
|
|
|
217
234
|
/**
|
|
218
235
|
* Returns current data
|