edfcore 0.2.35 → 0.2.37

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 CHANGED
@@ -6,6 +6,20 @@ 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.36
10
+
11
+ - **Fixed** `cachedSource` repopulating itself after `close()`. A read already in flight when close
12
+ was called still resolves, and its continuation still runs — after `blocks.clear()` — so the
13
+ cache refilled itself after being closed and then served that data on later reads, from a source
14
+ whose own `close` had already run. Admission is now refused once closed, so the cache stays empty
15
+ and every later read is delegated to the wrapped source, which behaves exactly as it would
16
+ without the wrapper.
17
+ - **Documented** why the oversized-read path returns the wrapped source's own array rather than a
18
+ copy. It looks like a violation of the "a cache hands back a copy" rule and is not: that rule
19
+ exists because a cache RETAINS its blocks, and a read wider than the whole budget bypasses the
20
+ cache entirely and retains nothing. The path is exactly as safe as calling the wrapped source
21
+ directly, which is what it does.
22
+
9
23
  ## 0.2.35
10
24
 
11
25
  - **Fixed** `byteSource` building a source over an argument that is not bytes, so the caller's
@@ -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.35";
112
+ export declare const VERSION = "0.2.37";
113
113
  //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -79,5 +79,5 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
79
79
  reserved: 224,
80
80
  };
81
81
  /** Published package version. Kept in sync with package.json by a test. */
82
- export const VERSION = '0.2.35';
82
+ export const VERSION = '0.2.37';
83
83
  //# sourceMappingURL=constants.js.map
@@ -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,CAyGnF"}
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;
@@ -1 +1 @@
1
- {"version":3,"file":"cached.js","sourceRoot":"","sources":["../../src/io/cached.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEpG,MAAM,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAAC;AACxC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C,yFAAyF;AACzF,SAAS,WAAW,CAAC,MAAkB;IACrC,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK,CAAC,IAAI,CAAC,MAAc,EAAE,MAAc,EAAE,OAAqB;YAC9D,OAAO,eAAe,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACrF,CAAC;QACD,KAAK,CAAC,KAAK;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,OAAsB;IACrE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CACvB,CAAC,EACD,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAClF,CAAC;IACF,MAAM,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAClC,CAAC,EAC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AAG,QAAQ,CAAC,GAAG,UAAU,CAAC;gBACxD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;gBAC1C,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;gBACpE,IAAI,EAAE,IAAI,IAAI;oBAAE,SAAS;gBACzB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,GAAG,UAAU,EAAE,EAAE,GAAG,UAAU,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC;YAC7E,CAAC;YACD,OAAO,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,KAAK;YACT,4FAA4F;YAC5F,8EAA8E;YAC9E,MAAM,GAAG,IAAI,CAAC;YACd,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,WAAW,GAAG,CAAC,CAAC;YAChB,MAAM,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edfcore",
3
- "version": "0.2.35",
3
+ "version": "0.2.37",
4
4
  "description": "Modern, typed, zero-dependency reader for EDF, EDF+, BDF and BDF+ biosignal files. Works in browsers and Node with true random access.",
5
5
  "keywords": [
6
6
  "edf",
package/src/constants.ts CHANGED
@@ -93,4 +93,4 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
93
93
  } as const;
94
94
 
95
95
  /** Published package version. Kept in sync with package.json by a test. */
96
- export const VERSION = '0.2.35';
96
+ export const VERSION = '0.2.37';
package/src/io/cached.ts CHANGED
@@ -64,8 +64,14 @@ export function cachedSource(source: 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;