bireader 1.0.56 → 1.0.59
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 +2 -2
- package/lib/cjs/index.cjs +19 -11
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/index.d.cts.map +1 -1
- package/lib/esm/index.d.mts.map +1 -1
- package/lib/esm/index.mjs +19 -11
- package/lib/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ function parse_webp(data){
|
|
|
169
169
|
|
|
170
170
|
//write example - write a webp file from read data
|
|
171
171
|
function write_webp(data){
|
|
172
|
-
const bw = new biwriter(new Uint8Arry(
|
|
172
|
+
const bw = new biwriter(new Uint8Arry(0x100000)) // Will extends array as we write if needed by default
|
|
173
173
|
bw.string("RIFF",{length:4})
|
|
174
174
|
bw.uint32le(0) //dummy for now, will be final size - 8
|
|
175
175
|
bw.string("WEBP",{length:4})
|
|
@@ -291,7 +291,7 @@ Common functions for setup, movement, manipulation and math shared by both.
|
|
|
291
291
|
<td>new bireader(<b>data</b>, byteOffset, bitOffset, endianess, strict)</td>
|
|
292
292
|
<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)
|
|
293
293
|
</td>
|
|
294
|
-
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b>
|
|
294
|
+
<td rowspan="2">Start with new Constructor.<br><br><b>Note:</b> Supplied data can always be found with .data.<br><br><b>biwriter 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 to start and use .trim() after you're finished.</td>
|
|
295
295
|
</tr>
|
|
296
296
|
<tr>
|
|
297
297
|
<td>Name</td>
|
package/lib/cjs/index.cjs
CHANGED
|
@@ -1226,11 +1226,15 @@ function rfloat(_this, endian) {
|
|
|
1226
1226
|
}
|
|
1227
1227
|
function wfloat(_this, value, endian) {
|
|
1228
1228
|
check_size(_this, 4, 0);
|
|
1229
|
-
const
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1229
|
+
const MIN_POSITIVE_FLOAT32 = Number.MIN_VALUE;
|
|
1230
|
+
const MAX_POSITIVE_FLOAT32 = 3.4028235e+38;
|
|
1231
|
+
const MIN_NEGATIVE_FLOAT32 = -3.4028235e+38;
|
|
1232
|
+
const MAX_NEGATIVE_FLOAT32 = -Number.MIN_VALUE;
|
|
1233
|
+
if (!((value === 0) ||
|
|
1234
|
+
(value >= MIN_POSITIVE_FLOAT32 && value <= MAX_POSITIVE_FLOAT32) ||
|
|
1235
|
+
(value >= MIN_NEGATIVE_FLOAT32 && value <= MAX_NEGATIVE_FLOAT32))) {
|
|
1232
1236
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
1233
|
-
throw new Error('Value is out of range for the specified float length.' + " min: " +
|
|
1237
|
+
throw new Error('Value is out of range for the specified float length.' + " min: " + MIN_NEGATIVE_FLOAT32 + " max: " + MAX_POSITIVE_FLOAT32 + " value: " + value);
|
|
1234
1238
|
}
|
|
1235
1239
|
const dataView = new DataView(new Uint8Array(4).buffer);
|
|
1236
1240
|
dataView.setFloat32(0, value, true);
|
|
@@ -1333,11 +1337,15 @@ function wint64(_this, value, unsigned, endian) {
|
|
|
1333
1337
|
}
|
|
1334
1338
|
function wdfloat(_this, value, endian) {
|
|
1335
1339
|
check_size(_this, 8, 0);
|
|
1336
|
-
const
|
|
1337
|
-
const
|
|
1338
|
-
|
|
1340
|
+
const MIN_POSITIVE_FLOAT64 = 2.2250738585072014e-308;
|
|
1341
|
+
const MAX_POSITIVE_FLOAT64 = Number.MAX_VALUE;
|
|
1342
|
+
const MIN_NEGATIVE_FLOAT64 = -Number.MAX_VALUE;
|
|
1343
|
+
const MAX_NEGATIVE_FLOAT64 = -2.2250738585072014e-308;
|
|
1344
|
+
if (!((value === 0) ||
|
|
1345
|
+
(value >= MIN_POSITIVE_FLOAT64 && value <= MAX_POSITIVE_FLOAT64) ||
|
|
1346
|
+
(value >= MIN_NEGATIVE_FLOAT64 && value <= MAX_NEGATIVE_FLOAT64))) {
|
|
1339
1347
|
_this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
|
|
1340
|
-
throw new Error('Value is out of range for the specified 64bit length.' + " min: " +
|
|
1348
|
+
throw new Error('Value is out of range for the specified 64bit length.' + " min: " + MIN_NEGATIVE_FLOAT64 + " max: " + MAX_POSITIVE_FLOAT64 + " value: " + value);
|
|
1341
1349
|
}
|
|
1342
1350
|
const intArray = new Int32Array(2);
|
|
1343
1351
|
const floatArray = new Float64Array(intArray.buffer);
|
|
@@ -1593,11 +1601,10 @@ function wstring(_this, string, options) {
|
|
|
1593
1601
|
}
|
|
1594
1602
|
var maxBytes = Math.min(string.length, maxLength);
|
|
1595
1603
|
const encodedString = encoder.encode(string.substring(0, maxBytes));
|
|
1596
|
-
var totalLength = (length || encodedString.length)
|
|
1604
|
+
var totalLength = (length || encodedString.length);
|
|
1597
1605
|
if (stringType == 'wide-pascal') {
|
|
1598
|
-
totalLength = (length || (encodedString.length * 2))
|
|
1606
|
+
totalLength = (length || (encodedString.length * 2));
|
|
1599
1607
|
}
|
|
1600
|
-
check_size(_this, totalLength, 0);
|
|
1601
1608
|
if (lengthWriteSize == 1) {
|
|
1602
1609
|
_this.writeUByte(maxBytes);
|
|
1603
1610
|
}
|
|
@@ -1607,6 +1614,7 @@ function wstring(_this, string, options) {
|
|
|
1607
1614
|
else if (lengthWriteSize == 4) {
|
|
1608
1615
|
_this.writeUInt32(maxBytes, endian);
|
|
1609
1616
|
}
|
|
1617
|
+
check_size(_this, totalLength, 0);
|
|
1610
1618
|
// Write the string bytes to the Uint8Array
|
|
1611
1619
|
for (let i = 0; i < encodedString.length; i++) {
|
|
1612
1620
|
if (stringType == 'wide-pascal') {
|