bireader 3.0.1 → 3.1.0
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 +91 -29
- package/dist/BiReader.d.ts +33 -0
- package/dist/BiReaderStream.d.ts +34 -0
- package/dist/BiWriter.d.ts +33 -0
- package/dist/BiWriterStream.d.ts +36 -0
- package/dist/aliases/BinaryAliasReader.d.ts +7 -0
- package/dist/aliases/BinaryAliasWriter.d.ts +7 -0
- package/dist/common.d.ts +90 -0
- package/{build/cjs/common.d.ts → dist/core/BiBase.d.ts} +132 -221
- package/dist/core/BiBaseStream.d.ts +1363 -0
- package/{build/esm/common.d.ts → dist/index.browser.d.ts} +208 -169
- package/dist/index.browser.js +9706 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs.d.ts +2895 -0
- package/dist/index.cjs.js +13662 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +2895 -0
- package/dist/index.esm.d.ts +2895 -0
- package/dist/index.esm.js +13635 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/indexBrowser.d.ts +19 -0
- package/dist/indexImport.d.ts +21 -0
- package/package.json +23 -14
- package/rollup.config.js +76 -0
- package/tsconfig.json +15 -0
- package/build/cjs/bireader.d.ts +0 -2372
- package/build/cjs/bireader.d.ts.map +0 -1
- package/build/cjs/bireader.js +0 -3060
- package/build/cjs/bireader.js.map +0 -1
- package/build/cjs/biwriter.d.ts +0 -2359
- package/build/cjs/biwriter.d.ts.map +0 -1
- package/build/cjs/biwriter.js +0 -3094
- package/build/cjs/biwriter.js.map +0 -1
- package/build/cjs/common.d.ts.map +0 -1
- package/build/cjs/common.js +0 -3615
- package/build/cjs/common.js.map +0 -1
- package/build/cjs/index.d.ts +0 -18
- package/build/cjs/index.d.ts.map +0 -1
- package/build/cjs/index.js +0 -30
- package/build/cjs/index.js.map +0 -1
- package/build/esm/bireader.d.ts +0 -2372
- package/build/esm/bireader.d.ts.map +0 -1
- package/build/esm/bireader.js +0 -3060
- package/build/esm/bireader.js.map +0 -1
- package/build/esm/biwriter.d.ts +0 -2359
- package/build/esm/biwriter.d.ts.map +0 -1
- package/build/esm/biwriter.js +0 -3094
- package/build/esm/biwriter.js.map +0 -1
- package/build/esm/common.d.ts.map +0 -1
- package/build/esm/common.js +0 -3615
- package/build/esm/common.js.map +0 -1
- package/build/esm/index.d.ts +0 -18
- package/build/esm/index.d.ts.map +0 -1
- package/build/esm/index.js +0 -30
- package/build/esm/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,16 +16,19 @@ Supported data types:
|
|
|
16
16
|
|
|
17
17
|
## What's New?
|
|
18
18
|
|
|
19
|
-
### v3
|
|
20
|
-
* Added
|
|
19
|
+
### v3
|
|
20
|
+
* Added Browser, Node CommonJS and Node ESM modules.
|
|
21
|
+
* Added new ``BiReaderStream`` and ``BiWriterStream`` for use in Node with large file size (4 gig+). See [documention](#bistreams) for how to use.
|
|
22
|
+
* Added setter ``.strSettings`` for use with ``.str`` for easier coding.
|
|
23
|
+
* Added better options for extending array buffer when writing data with ``extendBufferSize``.
|
|
21
24
|
* Consolidated all options argument into single object when creating class.
|
|
22
25
|
* Removed deprecated ``bireader`` and ``biwriter`` classes.
|
|
23
|
-
* Fixed standalone hexdump function.
|
|
26
|
+
* Fixed standalone ``hexdump`` function.
|
|
24
27
|
|
|
25
|
-
### v2
|
|
26
|
-
* Created new ``BiReader`` and ``BiWriter`` classes with
|
|
28
|
+
### v2
|
|
29
|
+
* Created new ``BiReader`` and ``BiWriter`` classes with *get* and *set* functions for easier coding.
|
|
27
30
|
|
|
28
|
-
### v1
|
|
31
|
+
### v1
|
|
29
32
|
* Included math functions and value searches.
|
|
30
33
|
* Many bug fixes.
|
|
31
34
|
|
|
@@ -33,7 +36,7 @@ Supported data types:
|
|
|
33
36
|
|
|
34
37
|
```npm install bireader```
|
|
35
38
|
|
|
36
|
-
Provides both CommonJS and ES modules.
|
|
39
|
+
Provides both CommonJS and ES modules for Browser and Node.
|
|
37
40
|
|
|
38
41
|
### Example
|
|
39
42
|
|
|
@@ -47,6 +50,7 @@ import {BiReader, BiWriter} from 'bireader';
|
|
|
47
50
|
// read example - parse a webp file
|
|
48
51
|
function parse_webp(data){
|
|
49
52
|
const br = new BiReader(data);
|
|
53
|
+
br.strSettings = {length: 4};
|
|
50
54
|
br.hexdump({supressUnicode:true}); // console.log data as hex
|
|
51
55
|
|
|
52
56
|
// 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
|
@@ -64,11 +68,11 @@ function parse_webp(data){
|
|
|
64
68
|
// 000b0 77 44 40 94 6d 25 6c 74 91 a8 88 86 58 9b da 6e wD@.m%lt....X..n
|
|
65
69
|
|
|
66
70
|
const header = {};
|
|
67
|
-
header.magic = br.
|
|
71
|
+
header.magic = br.str; // RIFF
|
|
68
72
|
header.size = br.uint32le; // 15000
|
|
69
73
|
header.fileSize = header.size + 8; // 15008
|
|
70
|
-
header.payload = br.
|
|
71
|
-
header.format = br.
|
|
74
|
+
header.payload = br.str; // WEBP
|
|
75
|
+
header.format = br.str; // VP8X
|
|
72
76
|
header.formatChunkSize = br.uint32le; // 10
|
|
73
77
|
switch (header.format){
|
|
74
78
|
case "VP8 ":
|
|
@@ -122,19 +126,19 @@ function parse_webp(data){
|
|
|
122
126
|
header.height = header.heightMinus1 + 1
|
|
123
127
|
if(header.I)
|
|
124
128
|
{
|
|
125
|
-
header.ICCP = br.
|
|
129
|
+
header.ICCP = br.str; // Should be ICCP
|
|
126
130
|
header.ICCPChunkSize = br.uint32;
|
|
127
131
|
header.ICCPData = br.extract(header.ICCPChunkSize, true);
|
|
128
132
|
}
|
|
129
133
|
if(header.L)
|
|
130
134
|
{
|
|
131
|
-
header.ALPH = br.
|
|
135
|
+
header.ALPH = br.str; // Should be ALPH
|
|
132
136
|
header.ALPHChunkSize = br.uint32; // 4134
|
|
133
137
|
header.ALPHData = br.extract(header.ALPHChunkSize, true);
|
|
134
138
|
}
|
|
135
139
|
if(header.A)
|
|
136
140
|
{
|
|
137
|
-
header.ANI = br.
|
|
141
|
+
header.ANI = br.str; // Should be ANIM or ANIF
|
|
138
142
|
header.ANIChunkSize = br.uint32;
|
|
139
143
|
if(header.ANI == "ANIM")
|
|
140
144
|
{
|
|
@@ -158,18 +162,18 @@ function parse_webp(data){
|
|
|
158
162
|
header.ANIFData = br.extract(header.ANIChunkSize, true);
|
|
159
163
|
}
|
|
160
164
|
}
|
|
161
|
-
header.extFormatStr = br.
|
|
165
|
+
header.extFormatStr = br.str;
|
|
162
166
|
header.extChunkSize = br.uint32;
|
|
163
167
|
header.extData = br.extract(header.extChunkSize, true);
|
|
164
168
|
if(header.E)
|
|
165
169
|
{
|
|
166
|
-
header.EXIF = br.
|
|
170
|
+
header.EXIF = br.str; // Should be EXIF
|
|
167
171
|
header.EXIFChunkSize = br.uint32;
|
|
168
172
|
header.EXIFData = br.extract(header.EXIFChunkSize, true);
|
|
169
173
|
}
|
|
170
174
|
if(header.X)
|
|
171
175
|
{
|
|
172
|
-
header.XMP = br.
|
|
176
|
+
header.XMP = br.str; // Should be XMP
|
|
173
177
|
header.XMPChunkSize = br.uint32;
|
|
174
178
|
header.XMPMetaData = br.extract(header.XMPChunkSize, true);
|
|
175
179
|
}
|
|
@@ -184,13 +188,15 @@ function parse_webp(data){
|
|
|
184
188
|
|
|
185
189
|
// write example - write a webp file from read data
|
|
186
190
|
function write_webp(data){
|
|
187
|
-
const bw = new BiWriter(new Uint8Arry(0x100000)); // Will extends array as we
|
|
188
|
-
|
|
191
|
+
const bw = new BiWriter(new Uint8Arry(0x100000)); // Will extends array as we
|
|
192
|
+
// write if needed by default
|
|
193
|
+
bw.strSettings = {length: 4};
|
|
194
|
+
bw.str = "RIFF";
|
|
189
195
|
bw.uint32le = 0; // dummy for now, will be final size - 8
|
|
190
|
-
bw.
|
|
196
|
+
bw.str = "WEBP";
|
|
191
197
|
switch(data.format){
|
|
192
198
|
case "VP8 ":
|
|
193
|
-
bw.
|
|
199
|
+
bw.str = "VP8 ";
|
|
194
200
|
bw.uint32le = data.VP8data.length;
|
|
195
201
|
bw.ubit24 = data.key_frame;
|
|
196
202
|
bw.ubit24 = data.start_code;
|
|
@@ -199,7 +205,7 @@ function write_webp(data){
|
|
|
199
205
|
bw.overwrite(data.VP8data ,true);
|
|
200
206
|
break;
|
|
201
207
|
case "VP8L":
|
|
202
|
-
bw.
|
|
208
|
+
bw.str = "VP8L";
|
|
203
209
|
bw.uint32le = data.VP8Ldata.length - 4;
|
|
204
210
|
bw.ubyte = 47;
|
|
205
211
|
bw.ubit14 = data.width - 1;
|
|
@@ -209,7 +215,7 @@ function write_webp(data){
|
|
|
209
215
|
bw.overwrite(data.VP8Ldata,true);
|
|
210
216
|
break;
|
|
211
217
|
case "VP8X":
|
|
212
|
-
bw.
|
|
218
|
+
bw.str = "VP8X";
|
|
213
219
|
bw.uint32le = 10;
|
|
214
220
|
bw.big();
|
|
215
221
|
bw.bit2 = 0;
|
|
@@ -225,19 +231,19 @@ function write_webp(data){
|
|
|
225
231
|
bw.ubit24 = data.height - 1;
|
|
226
232
|
if(data.I)
|
|
227
233
|
{
|
|
228
|
-
bw.
|
|
234
|
+
bw.str = data.ICCP;
|
|
229
235
|
bw.uint32 = data.ICCPData.length;;
|
|
230
236
|
bw.replace(data.ICCPData, true);
|
|
231
237
|
}
|
|
232
238
|
if(data.L)
|
|
233
239
|
{
|
|
234
|
-
bw.
|
|
240
|
+
bw.str = data.ALPH;
|
|
235
241
|
bw.uint32 = data.ALPHData.length;
|
|
236
242
|
bw.replace(data.ALPHData);
|
|
237
243
|
}
|
|
238
244
|
if(data.A)
|
|
239
245
|
{
|
|
240
|
-
bw.
|
|
246
|
+
bw.str = data.ANI;
|
|
241
247
|
bw.uint32 = data.ANIChunkSize;
|
|
242
248
|
if(data.ANI == "ANIM")
|
|
243
249
|
{
|
|
@@ -259,18 +265,18 @@ function write_webp(data){
|
|
|
259
265
|
bw.replace(data.ANIFData, true);
|
|
260
266
|
}
|
|
261
267
|
}
|
|
262
|
-
bw.
|
|
268
|
+
bw.str = data.extFormatStr;
|
|
263
269
|
bw.uint32 = data.extData.length;
|
|
264
270
|
bw.replace(data.extData, true);
|
|
265
271
|
if(data.E)
|
|
266
272
|
{
|
|
267
|
-
bw.
|
|
273
|
+
bw.str = data.EXIF;
|
|
268
274
|
bw.uint32 = data.EXIFData.length;
|
|
269
275
|
bw.replace( data.EXIFData, true);
|
|
270
276
|
}
|
|
271
277
|
if(data.X)
|
|
272
278
|
{
|
|
273
|
-
bw.
|
|
279
|
+
bw.str = data.XMP;
|
|
274
280
|
bw.uint32 = data.XMPMetaData.length;
|
|
275
281
|
bw.replace(data.XMPMetaData, true);
|
|
276
282
|
}
|
|
@@ -306,7 +312,7 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
306
312
|
<td>new BiReader(<b>data</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize})</td>
|
|
307
313
|
<td align="center" rowspan="2"><b>Buffer or Uint8Array</b>, byte offset (default 0), bit offset (default 0), endian big or little (default little), strict mode true to restrict extending initially supplied data (default true for reader, false for writer), extended Buffer size amount.
|
|
308
314
|
</td>
|
|
309
|
-
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> Supplied data can always be found with
|
|
315
|
+
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> Supplied data can always be found with <b>.data</b>.<br><br><b>Writing data note:</b> while BiWriter can be created with a 0 length Uint8Array or Buffer, each new value write will create a new array and concat the two. For large data writes this will lead to a degraded performance. It's best to supply a larger than needed buffer when creating the Writer and use <b>.trim()</b> after you're finished. You can also set the <b>extendBufferSize</b> value to always extend by a fixed amount when reaching the end. This will also change the logic for <b>.return</b> and <b>.get</b> to trim the remining data from the current position for you. Use <b>.data</b> instead if you want to get the whole padded buffer array.</td>
|
|
310
316
|
</tr>
|
|
311
317
|
<tr>
|
|
312
318
|
<td>Name</td>
|
|
@@ -735,6 +741,62 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
735
741
|
</tbody>
|
|
736
742
|
</table>
|
|
737
743
|
|
|
744
|
+
## BiStreams
|
|
745
|
+
|
|
746
|
+
With 3.1 you can now use ``BiReaderStream`` and ``BiWriterStream`` in Node for larger files (or if you don't want or need the whole file loaded to memory all at once).
|
|
747
|
+
|
|
748
|
+
<table>
|
|
749
|
+
<thead>
|
|
750
|
+
<tr>
|
|
751
|
+
<th align="center" colspan="2">Function</th>
|
|
752
|
+
<th align="center">Params (bold requires)</th>
|
|
753
|
+
<th align="left">Desc</th>
|
|
754
|
+
</tr>
|
|
755
|
+
</thead>
|
|
756
|
+
<tbody>
|
|
757
|
+
<tr>
|
|
758
|
+
<th align="center" colspan="4"><i>Streaming</i></th>
|
|
759
|
+
<tr>
|
|
760
|
+
<tr>
|
|
761
|
+
<td>Name</td>
|
|
762
|
+
<td>new BiReaderStream(<b>filePath</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize})</td>
|
|
763
|
+
<td align="center" rowspan="2"><b>Path to file</b>, byte offset (default 0), bit offset (default 0), endian big or little (default little), strict mode true to restrict extending file size (default true for reader, false for writer), extended file size amount.
|
|
764
|
+
</td>
|
|
765
|
+
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> The file must be opened with <b>.open()</b> and closed with <b>.close()</b>. The <b>.data</b> value is always the Buffer to the last read or write value. Read sizes outside of Node's max size will error, unless remove then it will create a new file.<br><br><b>Writer note:</b> You can set the <b>extendBufferSize</b> value to always extend the file by this minimum amount when reaching the end of the file. The file is saved after every write.</td>
|
|
766
|
+
</tr>
|
|
767
|
+
<tr>
|
|
768
|
+
<td>Name</td>
|
|
769
|
+
<td>new BiWriterStream(<b>filePath</b>, {byteOffset, bitOffset, endianess, strict, extendBufferSize})</td>
|
|
770
|
+
</tr>
|
|
771
|
+
<th align="center" colspan="4"><i>File Control</i></th>
|
|
772
|
+
<tr>
|
|
773
|
+
<td>Name</td>
|
|
774
|
+
<td>open()
|
|
775
|
+
<td align="center"><b>none</td>
|
|
776
|
+
<td>Opens file for reading / writing.</td>
|
|
777
|
+
</tr>
|
|
778
|
+
<tr>
|
|
779
|
+
<td>Name</td>
|
|
780
|
+
<td>close()
|
|
781
|
+
<td align="center"><b>none</td>
|
|
782
|
+
<td>Closes file after reading / writing.</td>
|
|
783
|
+
</tr>
|
|
784
|
+
<tr>
|
|
785
|
+
<td>Name</td>
|
|
786
|
+
<td>writeMode(writable)
|
|
787
|
+
<td align="center"><b>True if you want to switch to writing in BiReaderStream.</td>
|
|
788
|
+
<td>Note: This changes reader to write mode. Allows file to be expanded in size as well.</td>
|
|
789
|
+
</tr>
|
|
790
|
+
|
|
791
|
+
</tbody>
|
|
792
|
+
</table>
|
|
793
|
+
|
|
794
|
+
### Streaming Caveats
|
|
795
|
+
|
|
796
|
+
* Naming: Same naming applies to streamers as [Common Functions](#common-functions) section but the file is saved after every operation.
|
|
797
|
+
* Writing: Unlike the other BiReader, **all write functions will throw an error unless you switch to ``.writeMode(true)``** The file is read only until you do. Any write functions inside the reader will error beforehand.
|
|
798
|
+
* Large removal: When using any function that removes data from the file and would return a Buffer, **if the size of the returned Buffer is outside of the Node max size for a Buffer, a new file will be made with the location and size concat to the name with a .removed file extention instead.**
|
|
799
|
+
|
|
738
800
|
## Bit field
|
|
739
801
|
|
|
740
802
|
Parse value as a bit field. There are 32 functions from bit1 to bit32 and can be signed or unsigned (with a ``u`` at the start) and in little or big endian order (``be`` or ``le`` at the end).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BiOptions } from "./common.js";
|
|
3
|
+
import { BiBase } from './core/BiBase.js';
|
|
4
|
+
import { BinaryAliasReader } from "./aliases/BinaryAliasReader.js";
|
|
5
|
+
declare const BiReaderBase: typeof BiBase;
|
|
6
|
+
/**
|
|
7
|
+
* Binary reader, includes bitfields and strings.
|
|
8
|
+
*
|
|
9
|
+
* @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
|
|
10
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
11
|
+
* @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
|
|
12
|
+
* @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
|
|
13
|
+
* @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
14
|
+
* @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
|
|
15
|
+
* @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
16
|
+
*
|
|
17
|
+
* @since 2.0
|
|
18
|
+
*/
|
|
19
|
+
export declare class BiReader extends BiReaderBase implements BinaryAliasReader {
|
|
20
|
+
/**
|
|
21
|
+
* Binary reader, includes bitfields and strings.
|
|
22
|
+
*
|
|
23
|
+
* @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
|
|
24
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
25
|
+
* @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
|
|
26
|
+
* @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
|
|
27
|
+
* @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
28
|
+
* @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
|
|
29
|
+
* @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
30
|
+
*/
|
|
31
|
+
constructor(data: Buffer | Uint8Array, options?: BiOptions);
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BiOptions } from "./common.js";
|
|
2
|
+
import { BiBaseStreamer } from './core/BiBaseStream.js';
|
|
3
|
+
import { BinaryAliasReaderStreamer } from "./aliases/BinaryAliasReader.js";
|
|
4
|
+
declare const BiReaderStreamer: typeof BiBaseStreamer;
|
|
5
|
+
/**
|
|
6
|
+
* Binary reader, includes bitfields and strings.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} filePath - Path to file
|
|
9
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
10
|
+
* @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
|
|
11
|
+
* @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
|
|
12
|
+
* @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
13
|
+
* @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
|
|
14
|
+
* @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
15
|
+
*
|
|
16
|
+
* @since 3.1
|
|
17
|
+
*/
|
|
18
|
+
export declare class BiReaderStream extends BiReaderStreamer implements BinaryAliasReaderStreamer {
|
|
19
|
+
/**
|
|
20
|
+
* Binary reader, includes bitfields and strings.
|
|
21
|
+
*
|
|
22
|
+
* Note: Must start with .open() before reading.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} filePath - Path to file
|
|
25
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
26
|
+
* @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
|
|
27
|
+
* @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
|
|
28
|
+
* @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
29
|
+
* @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
|
|
30
|
+
* @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
31
|
+
*/
|
|
32
|
+
constructor(filePath: string, options?: BiOptions);
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BiOptions } from "./common.js";
|
|
3
|
+
import { BiBase } from './core/BiBase.js';
|
|
4
|
+
import { BinaryAliasWriter } from "./aliases/BinaryAliasWriter.js";
|
|
5
|
+
declare const BiWriterBase: typeof BiBase;
|
|
6
|
+
/**
|
|
7
|
+
* Binary writer, includes bitfields and strings.
|
|
8
|
+
*
|
|
9
|
+
* @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
|
|
10
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
11
|
+
* @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
|
|
12
|
+
* @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
|
|
13
|
+
* @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
14
|
+
* @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
|
|
15
|
+
* @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
16
|
+
*
|
|
17
|
+
* @since 2.0
|
|
18
|
+
*/
|
|
19
|
+
export declare class BiWriter extends BiWriterBase implements BinaryAliasWriter {
|
|
20
|
+
/**
|
|
21
|
+
* Binary writer, includes bitfields and strings.
|
|
22
|
+
*
|
|
23
|
+
* @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
|
|
24
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
25
|
+
* @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
|
|
26
|
+
* @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
|
|
27
|
+
* @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
28
|
+
* @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
|
|
29
|
+
* @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
30
|
+
*/
|
|
31
|
+
constructor(data?: Buffer | Uint8Array, options?: BiOptions);
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BiOptions } from "./common.js";
|
|
2
|
+
import { BiBaseStreamer } from './core/BiBaseStream.js';
|
|
3
|
+
import { BinaryAliasWriterStreamer } from "./aliases/BinaryAliasWriter.js";
|
|
4
|
+
declare const BiWriterStreamer: typeof BiBaseStreamer;
|
|
5
|
+
/**
|
|
6
|
+
* Binary writer, includes bitfields and strings.
|
|
7
|
+
*
|
|
8
|
+
* Note: Must start with .open() before writing.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} filePath - Path to file
|
|
11
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
12
|
+
* @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
|
|
13
|
+
* @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
|
|
14
|
+
* @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
15
|
+
* @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
|
|
16
|
+
* @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
17
|
+
*
|
|
18
|
+
* @since 3.1
|
|
19
|
+
*/
|
|
20
|
+
export declare class BiWriterStream extends BiWriterStreamer implements BinaryAliasWriterStreamer {
|
|
21
|
+
/**
|
|
22
|
+
* Binary writer, includes bitfields and strings.
|
|
23
|
+
*
|
|
24
|
+
* Note: Must start with .open() before writing.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} filePath - Path to file
|
|
27
|
+
* @param {BiOptions?} options - Any options to set at start
|
|
28
|
+
* @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
|
|
29
|
+
* @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
|
|
30
|
+
* @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
|
|
31
|
+
* @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
|
|
32
|
+
* @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
|
|
33
|
+
*/
|
|
34
|
+
constructor(filePath: string, options?: BiOptions);
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BiBase } from '../core/BiBase.js';
|
|
2
|
+
import { BiBaseStreamer } from '../core/BiBaseStream.js';
|
|
3
|
+
export interface BinaryAliasReader extends BiBase {
|
|
4
|
+
}
|
|
5
|
+
export interface BinaryAliasReaderStreamer extends BiBaseStreamer {
|
|
6
|
+
}
|
|
7
|
+
export declare function applyBinaryAliasReader<T extends new (...args: any[]) => any>(Base: T): T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BiBase } from '../core/BiBase.js';
|
|
2
|
+
import { BiBaseStreamer } from '../core/BiBaseStream.js';
|
|
3
|
+
export interface BinaryAliasWriter extends BiBase {
|
|
4
|
+
}
|
|
5
|
+
export interface BinaryAliasWriterStreamer extends BiBaseStreamer {
|
|
6
|
+
}
|
|
7
|
+
export declare function applyBinaryAliasWriter<T extends new (...args: any[]) => any>(Base: T): T;
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export type endian = "little" | "big";
|
|
3
|
+
export type BiOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Byte offset to start writer, default is 0
|
|
6
|
+
*/
|
|
7
|
+
byteOffset?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Byte offset to start writer, default is 0
|
|
10
|
+
*/
|
|
11
|
+
bitOffset?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Endianness ``big`` or ``little`` (default little)
|
|
14
|
+
*/
|
|
15
|
+
endianness?: endian;
|
|
16
|
+
/**
|
|
17
|
+
* Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
|
|
18
|
+
*/
|
|
19
|
+
strict?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Amount of data to add when extending the buffer array when strict mode is false. Note: Changes login in ``.get`` and ``.return``.
|
|
22
|
+
*/
|
|
23
|
+
extendBufferSize?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function isBuffer(obj: Buffer | Uint8Array): boolean;
|
|
26
|
+
export declare function arraybuffcheck(obj: Buffer | Uint8Array): boolean;
|
|
27
|
+
export type hexdumpOptions = {
|
|
28
|
+
/**
|
|
29
|
+
* number of bytes to log, default ``192`` or end of data
|
|
30
|
+
*/
|
|
31
|
+
length?: number;
|
|
32
|
+
/**
|
|
33
|
+
* byte to start dump (default ``0``)
|
|
34
|
+
*/
|
|
35
|
+
startByte?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Supress unicode character preview for even columns.
|
|
38
|
+
*/
|
|
39
|
+
supressUnicode?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the hex dump string instead of logging it.
|
|
42
|
+
*/
|
|
43
|
+
returnString?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Creates hex dump string. Will console log or return string if set in options.
|
|
47
|
+
*
|
|
48
|
+
* @param {Uint8Array|Buffer} src - Uint8Array or Buffer
|
|
49
|
+
* @param {hexdumpOptions?} options - hex dump options
|
|
50
|
+
* @param {number?} options.length - number of bytes to log, default ``192`` or end of data
|
|
51
|
+
* @param {number?} options.startByte - byte to start dump (default ``0``)
|
|
52
|
+
* @param {boolean?} options.supressUnicode - Supress unicode character preview for even columns.
|
|
53
|
+
* @param {boolean?} options.returnString - Returns the hex dump string instead of logging it.
|
|
54
|
+
*/
|
|
55
|
+
export declare function hexdump(src: Uint8Array | Buffer, options?: hexdumpOptions): void | string;
|
|
56
|
+
export declare function _hexDump(data: Buffer | Uint8Array, options: hexdumpOptions, start: number, end: number): string;
|
|
57
|
+
export type stringOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* for fixed length, non-terminate value utf strings
|
|
60
|
+
*/
|
|
61
|
+
length?: number;
|
|
62
|
+
/**
|
|
63
|
+
* utf-8, utf-16, pascal or wide-pascal
|
|
64
|
+
*/
|
|
65
|
+
stringType?: "utf-8" | "utf-16" | "pascal" | "wide-pascal";
|
|
66
|
+
/**
|
|
67
|
+
* only with stringType: "utf"
|
|
68
|
+
*/
|
|
69
|
+
terminateValue?: number;
|
|
70
|
+
/**
|
|
71
|
+
* for pascal strings. 1, 2 or 4 byte length read size
|
|
72
|
+
*/
|
|
73
|
+
lengthReadSize?: 1 | 2 | 4;
|
|
74
|
+
/**
|
|
75
|
+
* for pascal strings. 1, 2 or 4 byte length write size
|
|
76
|
+
*/
|
|
77
|
+
lengthWriteSize?: 1 | 2 | 4;
|
|
78
|
+
/**
|
|
79
|
+
* removes 0x00 characters
|
|
80
|
+
*/
|
|
81
|
+
stripNull?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* TextEncoder accepted types
|
|
84
|
+
*/
|
|
85
|
+
encoding?: string;
|
|
86
|
+
/**
|
|
87
|
+
* for wide-pascal and utf-16
|
|
88
|
+
*/
|
|
89
|
+
endian?: "big" | "little";
|
|
90
|
+
};
|