edfcore 0.5.61 → 0.5.62
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/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/io/bytes.d.ts.map +1 -1
- package/dist/io/bytes.js +28 -0
- package/dist/io/bytes.js.map +1 -1
- package/docs/CHANGELOG.md +18 -0
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/io/bytes.ts +32 -0
package/dist/constants.d.ts
CHANGED
|
@@ -109,5 +109,5 @@ export declare const SIGNAL_FIELD_BLOCK_OFFSETS: {
|
|
|
109
109
|
readonly reserved: 224;
|
|
110
110
|
};
|
|
111
111
|
/** Published package version. Kept in sync with package.json by a test. */
|
|
112
|
-
export declare const VERSION = "0.5.
|
|
112
|
+
export declare const VERSION = "0.5.62";
|
|
113
113
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.js
CHANGED
package/dist/io/bytes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/io/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/io/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAsD3D;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,GAAG,UAAU,CAkDtE"}
|
package/dist/io/bytes.js
CHANGED
|
@@ -43,6 +43,24 @@ function describe(value) {
|
|
|
43
43
|
* reason and this one was missed.
|
|
44
44
|
*/
|
|
45
45
|
const BUFFER_TAGS = new Set(['[object ArrayBuffer]', '[object SharedArrayBuffer]']);
|
|
46
|
+
/**
|
|
47
|
+
* Whether a buffer's bytes have been transferred away — `postMessage(bytes, [bytes.buffer])`, or
|
|
48
|
+
* `ArrayBuffer.prototype.transfer()`. A view over one keeps its tag and reports a `byteLength` of
|
|
49
|
+
* 0, so nothing else here can tell it apart from an empty array.
|
|
50
|
+
*
|
|
51
|
+
* `slice` rather than `ArrayBuffer.prototype.detached`, which says this in one word and arrives in
|
|
52
|
+
* ES2024 — above the ES2022 floor `browser-floor.test.ts` pins. A `SharedArrayBuffer` never
|
|
53
|
+
* detaches and answers false.
|
|
54
|
+
*/
|
|
55
|
+
function isDetachedBuffer(buffer) {
|
|
56
|
+
try {
|
|
57
|
+
buffer.slice(0, 0);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
46
64
|
/**
|
|
47
65
|
* A `ByteSource` over bytes already in memory, for a file you fetched yourself or a fixture in a
|
|
48
66
|
* test. The signedness of the view is checked at construction rather than at first read: an
|
|
@@ -65,6 +83,16 @@ export function byteSource(bytes) {
|
|
|
65
83
|
'ArrayBuffer itself. An Int8Array is not accepted — it has one byte per element, so it ' +
|
|
66
84
|
'would pass every length check and then decode to fabricated sample values.', { offset: 0, requestedLength: 0 });
|
|
67
85
|
}
|
|
86
|
+
// Refused at construction for the same reason, and it is the case the worker story produces:
|
|
87
|
+
// transferring bytes to a worker detaches the sender's buffer, and a view over it is still a
|
|
88
|
+
// Uint8Array with the right tag and a byteLength of 0. Building a source over that reports
|
|
89
|
+
// `[SOURCE_TOO_SMALL] the header is 0 bytes` — blaming the FILE for an argument the caller no
|
|
90
|
+
// longer owns.
|
|
91
|
+
if (isDetachedBuffer(isByteArray(bytes) ? bytes.buffer : bytes)) {
|
|
92
|
+
throw new EdfSourceError('byteSource() received a detached ArrayBuffer: its bytes were transferred to another ' +
|
|
93
|
+
'realm, so this one holds none of them. Next: read the file on the side that owns the ' +
|
|
94
|
+
'bytes now, or post them without a transfer list so both sides keep a copy.', { offset: 0, requestedLength: 0 });
|
|
95
|
+
}
|
|
68
96
|
// `isByteArray` rather than `instanceof Uint8Array`: `instanceof` is false for a view that
|
|
69
97
|
// crossed a realm boundary (a worker, an iframe), and this is a public entry point.
|
|
70
98
|
const view = isByteArray(bytes) ? bytes : new Uint8Array(bytes);
|
package/dist/io/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/io/bytes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE5F;;;;;;;;;;GAUG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACzF,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,eAAe,CAAC;IACjD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,KAAK,OAAO,KAAK,EAAE,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,sBAAsB,EAAE,4BAA4B,CAAC,CAAC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAA+B;IACxD,+FAA+F;IAC/F,+FAA+F;IAC/F,+FAA+F;IAC/F,g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ANGED
|
@@ -6,6 +6,24 @@ alone does not tell you whether you were affected.
|
|
|
6
6
|
edfcore is pre-1.0. Patch releases have carried behaviour changes where the old behaviour was a
|
|
7
7
|
defect; those are called out below.
|
|
8
8
|
|
|
9
|
+
## 0.5.62
|
|
10
|
+
|
|
11
|
+
- **Fixed** `byteSource` accepting a detached `ArrayBuffer` and building a zero-byte source over
|
|
12
|
+
it. `openEdf` then reported `[SOURCE_TOO_SMALL] the header is 0 bytes` — blaming the FILE for an
|
|
13
|
+
argument the caller no longer owns, which is the one confusion this constructor's own comment
|
|
14
|
+
says it exists to avoid. It refuses at construction now, with a message naming the transfer.
|
|
15
|
+
- A detached view is not an exotic input: `postMessage(bytes, [bytes.buffer])` is the ordinary way
|
|
16
|
+
to hand a recording to a worker, and it detaches the SENDER's buffer. A worker page that posts
|
|
17
|
+
the bytes and then opens them locally, or that transfers by mistake where it meant to copy, gets
|
|
18
|
+
a diagnostic about a file that is fine.
|
|
19
|
+
- Nothing else about the guard moves. A view over a detached buffer keeps its `Uint8Array` tag and
|
|
20
|
+
reports a `byteLength` of 0, so neither the tag test nor a length check can tell it from an empty
|
|
21
|
+
array — and a genuinely empty `Uint8Array` is still accepted and still reaches `SOURCE_TOO_SMALL`,
|
|
22
|
+
which for zero bytes you actually hold is the truthful answer. A `SharedArrayBuffer` never
|
|
23
|
+
detaches and is unaffected.
|
|
24
|
+
- The check is `buffer.slice(0, 0)` rather than `ArrayBuffer.prototype.detached`, which says it in
|
|
25
|
+
one word and arrives in ES2024 — above the ES2022 floor `browser-floor.test.ts` pins.
|
|
26
|
+
|
|
9
27
|
## 0.5.61
|
|
10
28
|
|
|
11
29
|
- **Fixed** a sentence both `api-errors.md` and `diagnostics.md` end their cross-realm advice with,
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
package/src/io/bytes.ts
CHANGED
|
@@ -44,6 +44,24 @@ function describe(value: unknown): string {
|
|
|
44
44
|
*/
|
|
45
45
|
const BUFFER_TAGS = new Set(['[object ArrayBuffer]', '[object SharedArrayBuffer]']);
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Whether a buffer's bytes have been transferred away — `postMessage(bytes, [bytes.buffer])`, or
|
|
49
|
+
* `ArrayBuffer.prototype.transfer()`. A view over one keeps its tag and reports a `byteLength` of
|
|
50
|
+
* 0, so nothing else here can tell it apart from an empty array.
|
|
51
|
+
*
|
|
52
|
+
* `slice` rather than `ArrayBuffer.prototype.detached`, which says this in one word and arrives in
|
|
53
|
+
* ES2024 — above the ES2022 floor `browser-floor.test.ts` pins. A `SharedArrayBuffer` never
|
|
54
|
+
* detaches and answers false.
|
|
55
|
+
*/
|
|
56
|
+
function isDetachedBuffer(buffer: ArrayBufferLike): boolean {
|
|
57
|
+
try {
|
|
58
|
+
buffer.slice(0, 0);
|
|
59
|
+
return false;
|
|
60
|
+
} catch {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
/**
|
|
48
66
|
* A `ByteSource` over bytes already in memory, for a file you fetched yourself or a fixture in a
|
|
49
67
|
* test. The signedness of the view is checked at construction rather than at first read: an
|
|
@@ -70,6 +88,20 @@ export function byteSource(bytes: ArrayBuffer | Uint8Array): ByteSource {
|
|
|
70
88
|
);
|
|
71
89
|
}
|
|
72
90
|
|
|
91
|
+
// Refused at construction for the same reason, and it is the case the worker story produces:
|
|
92
|
+
// transferring bytes to a worker detaches the sender's buffer, and a view over it is still a
|
|
93
|
+
// Uint8Array with the right tag and a byteLength of 0. Building a source over that reports
|
|
94
|
+
// `[SOURCE_TOO_SMALL] the header is 0 bytes` — blaming the FILE for an argument the caller no
|
|
95
|
+
// longer owns.
|
|
96
|
+
if (isDetachedBuffer(isByteArray(bytes) ? bytes.buffer : (bytes as ArrayBuffer))) {
|
|
97
|
+
throw new EdfSourceError(
|
|
98
|
+
'byteSource() received a detached ArrayBuffer: its bytes were transferred to another ' +
|
|
99
|
+
'realm, so this one holds none of them. Next: read the file on the side that owns the ' +
|
|
100
|
+
'bytes now, or post them without a transfer list so both sides keep a copy.',
|
|
101
|
+
{ offset: 0, requestedLength: 0 },
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
73
105
|
// `isByteArray` rather than `instanceof Uint8Array`: `instanceof` is false for a view that
|
|
74
106
|
// crossed a realm boundary (a worker, an iframe), and this is a public entry point.
|
|
75
107
|
const view: Uint8Array = isByteArray(bytes) ? bytes : new Uint8Array(bytes as ArrayBuffer);
|