edfcore 0.2.35 → 0.2.38
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/CHANGELOG.md +23 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/io/cached.d.ts.map +1 -1
- package/dist/io/cached.js +14 -2
- package/dist/io/cached.js.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +6 -0
- package/dist/node.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/io/cached.ts +15 -2
- package/src/node.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ 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.2.37
|
|
10
|
+
|
|
11
|
+
- **Fixed** `fileHandleSource` and `fileSource` ignoring an abort signal that flipped while a read
|
|
12
|
+
was in flight. The abort check ran at the top of each loop iteration, and the common case is one
|
|
13
|
+
syscall that returns everything — so the check ran once, before it, and a caller who gave up
|
|
14
|
+
during the read got the data anyway. `blobSource` has always re-checked after its await, with a
|
|
15
|
+
test saying why; one adapter honouring a signal that another quietly ignores is worse than either
|
|
16
|
+
rule alone.
|
|
17
|
+
|
|
18
|
+
## 0.2.36
|
|
19
|
+
|
|
20
|
+
- **Fixed** `cachedSource` repopulating itself after `close()`. A read already in flight when close
|
|
21
|
+
was called still resolves, and its continuation still runs — after `blocks.clear()` — so the
|
|
22
|
+
cache refilled itself after being closed and then served that data on later reads, from a source
|
|
23
|
+
whose own `close` had already run. Admission is now refused once closed, so the cache stays empty
|
|
24
|
+
and every later read is delegated to the wrapped source, which behaves exactly as it would
|
|
25
|
+
without the wrapper.
|
|
26
|
+
- **Documented** why the oversized-read path returns the wrapped source's own array rather than a
|
|
27
|
+
copy. It looks like a violation of the "a cache hands back a copy" rule and is not: that rule
|
|
28
|
+
exists because a cache RETAINS its blocks, and a read wider than the whole budget bypasses the
|
|
29
|
+
cache entirely and retains nothing. The path is exactly as safe as calling the wrapped source
|
|
30
|
+
directly, which is what it does.
|
|
31
|
+
|
|
9
32
|
## 0.2.35
|
|
10
33
|
|
|
11
34
|
- **Fixed** `byteSource` building a source over an argument that is not bytes, so the caller's
|
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.2.
|
|
112
|
+
export declare const VERSION = "0.2.38";
|
|
113
113
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.js
CHANGED
package/dist/io/cached.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached.d.ts","sourceRoot":"","sources":["../../src/io/cached.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AAmBzE,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"cached.d.ts","sourceRoot":"","sources":["../../src/io/cached.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AAmBzE,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,UAAU,CAsHnF"}
|
package/dist/io/cached.js
CHANGED
|
@@ -52,8 +52,13 @@ export function cachedSource(source, options) {
|
|
|
52
52
|
cachedBytes -= block.byteLength;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
// Set by `close()`. A read that was already in flight when close was called still resolves, and
|
|
56
|
+
// its `.then` still runs — after `blocks.clear()` — so without this the cache repopulated itself
|
|
57
|
+
// AFTER being closed and then served that data on later reads, from a source whose own `close`
|
|
58
|
+
// had already run. `admit` is where that happens, so `admit` is where it is stopped.
|
|
59
|
+
let closed = false;
|
|
55
60
|
function admit(index, block) {
|
|
56
|
-
if (blocks.has(index))
|
|
61
|
+
if (closed || blocks.has(index))
|
|
57
62
|
return;
|
|
58
63
|
blocks.set(index, block);
|
|
59
64
|
cachedBytes += block.byteLength;
|
|
@@ -95,7 +100,11 @@ export function cachedSource(source, options) {
|
|
|
95
100
|
if (length === 0)
|
|
96
101
|
return new Uint8Array(0);
|
|
97
102
|
// A read wider than the entire budget cannot benefit from the cache and would evict every
|
|
98
|
-
// block on its way through, so it goes straight to the source.
|
|
103
|
+
// block on its way through, so it goes straight to the source. The array is the wrapped
|
|
104
|
+
// source's own, not a copy, and that is correct rather than an oversight: the "a cache hands
|
|
105
|
+
// back a copy" rule exists because a cache RETAINS its blocks, and nothing is retained here.
|
|
106
|
+
// This path is exactly as safe as calling the wrapped source directly, because that is what
|
|
107
|
+
// it does.
|
|
99
108
|
if (length > maxBytes) {
|
|
100
109
|
return assertExactRead(await source.read(offset, length, options), offset, length);
|
|
101
110
|
}
|
|
@@ -119,6 +128,9 @@ export function cachedSource(source, options) {
|
|
|
119
128
|
return assertExactRead(out, offset, length);
|
|
120
129
|
},
|
|
121
130
|
async close() {
|
|
131
|
+
// Order matters only in that `closed` must be set before anything awaits: an in-flight read
|
|
132
|
+
// can resolve during `source.close()` and would otherwise re-admit its block.
|
|
133
|
+
closed = true;
|
|
122
134
|
blocks.clear();
|
|
123
135
|
inflight.clear();
|
|
124
136
|
cachedBytes = 0;
|
package/dist/io/cached.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cached.js","sourceRoot":"","sources":["../../src/io/cached.ts"],"names":[],"mappings":"AAAA;;;;;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,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAOH,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,YAAY,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,CACF,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,CAgCvF;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBlE"}
|
package/dist/node.js
CHANGED
|
@@ -69,6 +69,12 @@ export function fileHandleSource(handle, byteLength) {
|
|
|
69
69
|
break;
|
|
70
70
|
filled += bytesRead;
|
|
71
71
|
}
|
|
72
|
+
// Checked again AFTER the syscalls, not only before each one. The common case is a single
|
|
73
|
+
// read that returns everything, so the loop's check ran once, before it — and a signal that
|
|
74
|
+
// flipped while the syscall was in flight was ignored and the data returned anyway.
|
|
75
|
+
// `blobSource` has always rejected in that situation, and one adapter honouring a signal
|
|
76
|
+
// that another quietly ignores is worse than either rule on its own.
|
|
77
|
+
throwIfAborted(options);
|
|
72
78
|
return assertExactRead(buffer.subarray(0, filled), offset, length);
|
|
73
79
|
},
|
|
74
80
|
async close() {
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,4FAA4F;AAC5F,2FAA2F;AAC3F,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA2BlF,MAAM,EAAE,GAAmB,cAA2C,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAsB,EAAE,UAAkB;IACzE,OAAO;QACL,UAAU;QACV,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,MAAc,EAAE,OAAqB;YAC9D,cAAc,CAAC,OAAO,CAAC,CAAC;YACxB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YAC5C,IAAI,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;YAE3C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YACtC,IAAI,MAAM,GAAG,CAAC,CAAC;YACf,OAAO,MAAM,GAAG,MAAM,EAAE,CAAC;gBACvB,cAAc,CAAC,OAAO,CAAC,CAAC;gBACxB,wFAAwF;gBACxF,0DAA0D;gBAC1D,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG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: ByteSource, options?: CacheOptions): ByteSo
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
// Set by `close()`. A read that was already in flight when close was called still resolves, and
|
|
68
|
+
// its `.then` still runs — after `blocks.clear()` — so without this the cache repopulated itself
|
|
69
|
+
// AFTER being closed and then served that data on later reads, from a source whose own `close`
|
|
70
|
+
// had already run. `admit` is where that happens, so `admit` is where it is stopped.
|
|
71
|
+
let closed = false;
|
|
72
|
+
|
|
67
73
|
function admit(index: number, block: Uint8Array): void {
|
|
68
|
-
if (blocks.has(index)) return;
|
|
74
|
+
if (closed || blocks.has(index)) return;
|
|
69
75
|
blocks.set(index, block);
|
|
70
76
|
cachedBytes += block.byteLength;
|
|
71
77
|
evict();
|
|
@@ -108,7 +114,11 @@ export function cachedSource(source: ByteSource, options?: CacheOptions): ByteSo
|
|
|
108
114
|
assertReadRange(offset, length, byteLength);
|
|
109
115
|
if (length === 0) return new Uint8Array(0);
|
|
110
116
|
// A read wider than the entire budget cannot benefit from the cache and would evict every
|
|
111
|
-
// block on its way through, so it goes straight to the source.
|
|
117
|
+
// block on its way through, so it goes straight to the source. The array is the wrapped
|
|
118
|
+
// source's own, not a copy, and that is correct rather than an oversight: the "a cache hands
|
|
119
|
+
// back a copy" rule exists because a cache RETAINS its blocks, and nothing is retained here.
|
|
120
|
+
// This path is exactly as safe as calling the wrapped source directly, because that is what
|
|
121
|
+
// it does.
|
|
112
122
|
if (length > maxBytes) {
|
|
113
123
|
return assertExactRead(await source.read(offset, length, options), offset, length);
|
|
114
124
|
}
|
|
@@ -133,6 +143,9 @@ export function cachedSource(source: ByteSource, options?: CacheOptions): ByteSo
|
|
|
133
143
|
return assertExactRead(out, offset, length);
|
|
134
144
|
},
|
|
135
145
|
async close(): Promise<void> {
|
|
146
|
+
// Order matters only in that `closed` must be set before anything awaits: an in-flight read
|
|
147
|
+
// can resolve during `source.close()` and would otherwise re-admit its block.
|
|
148
|
+
closed = true;
|
|
136
149
|
blocks.clear();
|
|
137
150
|
inflight.clear();
|
|
138
151
|
cachedBytes = 0;
|
package/src/node.ts
CHANGED
|
@@ -96,6 +96,12 @@ export function fileHandleSource(handle: FileHandleLike, byteLength: number): By
|
|
|
96
96
|
if (bytesRead <= 0) break;
|
|
97
97
|
filled += bytesRead;
|
|
98
98
|
}
|
|
99
|
+
// Checked again AFTER the syscalls, not only before each one. The common case is a single
|
|
100
|
+
// read that returns everything, so the loop's check ran once, before it — and a signal that
|
|
101
|
+
// flipped while the syscall was in flight was ignored and the data returned anyway.
|
|
102
|
+
// `blobSource` has always rejected in that situation, and one adapter honouring a signal
|
|
103
|
+
// that another quietly ignores is worse than either rule on its own.
|
|
104
|
+
throwIfAborted(options);
|
|
99
105
|
return assertExactRead(buffer.subarray(0, filled), offset, length);
|
|
100
106
|
},
|
|
101
107
|
async close(): Promise<void> {
|