bireader 1.0.4 → 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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Read and write data in binary",
5
5
  "main": "index.js",
6
6
  "directories": {
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
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