Skip to content

Commit 45a61f4

Browse files
authored
Merge pull request #258 from effigies/deno/2.5
type: Adapt to changes in ArrayBuffers in Typescript 5.9.2
2 parents 154c85c + 80bacb4 commit 45a61f4

File tree

8 files changed

+79
-28
lines changed

8 files changed

+79
-28
lines changed

.github/workflows/deno_tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: echo version=$( git describe ) >> $GITHUB_OUTPUT
3939
- uses: denoland/setup-deno@v2
4040
with:
41-
deno-version: v2.4
41+
deno-version: v2.x
4242
- run: deno --node-modules-dir=auto -A ./build.ts
4343
- run: deno run -A ./dist/validator/bids-validator.js --version
4444
- uses: actions/upload-artifact@v4
@@ -64,7 +64,7 @@ jobs:
6464
submodules: true
6565
- uses: denoland/setup-deno@v2
6666
with:
67-
deno-version: v2.4
67+
deno-version: v2.x
6868
- name: Set permissions with network access
6969
run: echo 'PERMS=--allow-read --allow-write --allow-env --allow-run --allow-net' >> $GITHUB_ENV
7070
if: ${{ matrix.allow-net }}
@@ -98,7 +98,7 @@ jobs:
9898
- uses: actions/checkout@v4
9999
- uses: denoland/setup-deno@v2
100100
with:
101-
deno-version: v2.4
101+
deno-version: v2.x
102102
- run: deno publish --dry-run
103103

104104
publish:
@@ -117,7 +117,7 @@ jobs:
117117
TAG: ${{ github.ref_name }}
118118
- uses: denoland/setup-deno@v2
119119
with:
120-
deno-version: v2.4
120+
deno-version: v2.x
121121
- run: deno publish
122122

123123
deploy:

.github/workflows/web_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- uses: actions/checkout@v4
2828
- uses: denoland/setup-deno@v2
2929
with:
30-
deno-version: v2.4
30+
deno-version: v2.x
3131
- run: deno task build
3232
working-directory: ./web
3333
- name: Upload GitHub Pages artifact
@@ -52,7 +52,7 @@ jobs:
5252
path: dev
5353
- uses: denoland/setup-deno@v2
5454
with:
55-
deno-version: v2.4
55+
deno-version: v2.x
5656
- name: Build release/target
5757
run: deno task build
5858
working-directory: stable/web
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Added
10+
11+
- A bullet item for the Added category.
12+
13+
-->
14+
### Changed
15+
16+
- Now supports Deno 2.5 and Typescript 5.9.2.
17+
18+
<!--
19+
### Fixed
20+
21+
- A bullet item for the Fixed category.
22+
23+
-->
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Removed
32+
33+
- A bullet item for the Removed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->
42+
<!--
43+
### Infrastructure
44+
45+
- A bullet item for the Infrastructure category.
46+
47+
-->

src/files/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class BIDSFileBrowser implements BIDSFile {
2929
return this.#file.size
3030
}
3131

32-
get stream(): ReadableStream<Uint8Array> {
33-
return this.#file.stream()
32+
get stream(): ReadableStream<Uint8Array<ArrayBuffer>> {
33+
return this.#file.stream() as ReadableStream<Uint8Array<ArrayBuffer>>
3434
}
3535

3636
get ignored(): boolean {

src/files/deno.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class BIDSFileDeno implements BIDSFile {
4545
return this.#fileInfo ? this.#fileInfo.size : -1
4646
}
4747

48-
get stream(): ReadableStream<Uint8Array> {
48+
get stream(): ReadableStream<Uint8Array<ArrayBuffer>> {
4949
const handle = this.#openHandle()
5050
return handle.readable
5151
}

src/files/tsv.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { loadTSV, loadTSVGZ } from './tsv.ts'
1010
import { streamFromString } from '../tests/utils.ts'
1111
import { ColumnsMap } from '../types/columns.ts'
1212

13+
function compressedStreamFromString(str: string): ReadableStream<Uint8Array<ArrayBuffer>> {
14+
return streamFromString(str).pipeThrough(new CompressionStream('gzip')) as ReadableStream<
15+
Uint8Array<ArrayBuffer>
16+
>
17+
}
18+
1319
Deno.test('TSV loading', async (t) => {
1420
await t.step('Empty file produces empty map', async () => {
1521
const file = pathToFile('/empty.tsv')
@@ -182,7 +188,7 @@ Deno.test('TSV loading', async (t) => {
182188
Deno.test('TSVGZ loading', async (t) => {
183189
await t.step('No header and empty file produces empty map', async () => {
184190
const file = pathToFile('/empty.tsv.gz')
185-
file.stream = streamFromString('').pipeThrough(new CompressionStream('gzip'))
191+
file.stream = compressedStreamFromString('')
186192

187193
const map = await loadTSVGZ(file, [])
188194
// map.size looks for a column called map, so work around it
@@ -191,7 +197,7 @@ Deno.test('TSVGZ loading', async (t) => {
191197

192198
await t.step('Empty file produces header-only map', async () => {
193199
const file = pathToFile('/empty.tsv.gz')
194-
file.stream = streamFromString('').pipeThrough(new CompressionStream('gzip'))
200+
file.stream = compressedStreamFromString('')
195201

196202
const map = await loadTSVGZ(file, ['a', 'b', 'c'])
197203
assertEquals(map.a, [])
@@ -201,15 +207,15 @@ Deno.test('TSVGZ loading', async (t) => {
201207

202208
await t.step('Single column file produces single column maps', async () => {
203209
const file = pathToFile('/single_column.tsv')
204-
file.stream = streamFromString('1\n2\n3\n').pipeThrough(new CompressionStream('gzip'))
210+
file.stream = compressedStreamFromString('1\n2\n3\n')
205211

206212
const map = await loadTSVGZ(file, ['a'])
207213
assertEquals(map.a, ['1', '2', '3'])
208214
})
209215

210216
await t.step('Mismatched header length throws issue', async () => {
211217
const file = pathToFile('/single_column.tsv.gz')
212-
file.stream = streamFromString('1\n2\n3\n').pipeThrough(new CompressionStream('gzip'))
218+
file.stream = compressedStreamFromString('1\n2\n3\n')
213219

214220
try {
215221
await loadTSVGZ(file, ['a', 'b'])
@@ -220,17 +226,15 @@ Deno.test('TSVGZ loading', async (t) => {
220226

221227
await t.step('Missing final newline is ignored', async () => {
222228
const file = pathToFile('/missing_newline.tsv.gz')
223-
file.stream = streamFromString('1\n2\n3').pipeThrough(new CompressionStream('gzip'))
229+
file.stream = compressedStreamFromString('1\n2\n3')
224230

225231
const map = await loadTSVGZ(file, ['a'])
226232
assertEquals(map.a, ['1', '2', '3'])
227233
})
228234

229235
await t.step('Empty row throws issue', async () => {
230236
const file = pathToFile('/empty_row.tsv.gz')
231-
file.stream = streamFromString('1\t2\t3\n\n4\t5\t6\n').pipeThrough(
232-
new CompressionStream('gzip'),
233-
)
237+
file.stream = compressedStreamFromString('1\t2\t3\n\n4\t5\t6\n')
234238

235239
try {
236240
await loadTSVGZ(file, ['a', 'b', 'c'])
@@ -255,35 +259,33 @@ Deno.test('TSVGZ loading', async (t) => {
255259
// Use 1500 to avoid overlap with default initial capacity
256260
const headers = ['a', 'b', 'c']
257261
const text = '1\t2\t3\n'.repeat(1500)
258-
file.stream = streamFromString(text).pipeThrough(new CompressionStream('gzip'))
262+
file.stream = compressedStreamFromString(text)
259263

260264
let map = await loadTSVGZ(file, headers, 0)
261265
assertEquals(map.a, [])
262266
assertEquals(map.b, [])
263267
assertEquals(map.c, [])
264268

265-
file.stream = streamFromString(text).pipeThrough(new CompressionStream('gzip'))
269+
file.stream = compressedStreamFromString(text)
266270
map = await loadTSVGZ(file, headers, 1)
267271
assertEquals(map.a, ['1'])
268272
assertEquals(map.b, ['2'])
269273
assertEquals(map.c, ['3'])
270274

271-
file.stream = streamFromString(text).pipeThrough(new CompressionStream('gzip'))
275+
file.stream = compressedStreamFromString(text)
272276
map = await loadTSVGZ(file, headers, 2)
273277
assertEquals(map.a, ['1', '1'])
274278
assertEquals(map.b, ['2', '2'])
275279
assertEquals(map.c, ['3', '3'])
276280

277-
file.stream = streamFromString(text).pipeThrough(new CompressionStream('gzip'))
281+
file.stream = compressedStreamFromString(text)
278282
map = await loadTSVGZ(file, headers, -1)
279283
assertEquals(map.a, Array(1500).fill('1'))
280284
assertEquals(map.b, Array(1500).fill('2'))
281285
assertEquals(map.c, Array(1500).fill('3'))
282286

283287
// Check that maxRows does not truncate shorter files
284-
file.stream = streamFromString('1\t2\t3\n4\t5\t6\n7\t8\t9\n').pipeThrough(
285-
new CompressionStream('gzip'),
286-
)
288+
file.stream = compressedStreamFromString('1\t2\t3\n4\t5\t6\n7\t8\t9\n')
287289
map = await loadTSVGZ(file, headers, 4)
288290
assertEquals(map.a, ['1', '4', '7'])
289291
assertEquals(map.b, ['2', '5', '8'])

src/tests/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function streamFromUint8Array(arr: Uint8Array): ReadableStream<Uint8Array> {
1+
export function streamFromUint8Array<T extends ArrayBufferLike>(
2+
arr: Uint8Array<T>,
3+
): ReadableStream<Uint8Array<T>> {
24
return new ReadableStream({
35
start(controller) {
46
controller.enqueue(arr)
@@ -7,6 +9,6 @@ export function streamFromUint8Array(arr: Uint8Array): ReadableStream<Uint8Array
79
})
810
}
911

10-
export function streamFromString(str: string): ReadableStream<Uint8Array> {
11-
return streamFromUint8Array(new TextEncoder().encode(str))
12+
export function streamFromString(str: string): ReadableStream<Uint8Array<ArrayBuffer>> {
13+
return streamFromUint8Array(new TextEncoder().encode(str) as Uint8Array<ArrayBuffer>)
1214
}

src/types/filetree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface BIDSFile {
1010
// BIDS ignore status of the file
1111
ignored: boolean
1212
// ReadableStream to file raw contents
13-
stream: ReadableStream<Uint8Array>
13+
stream: ReadableStream<Uint8Array<ArrayBuffer>>
1414
// Resolve stream to decoded utf-8 text
1515
text: () => Promise<string>
1616
// Read a range of bytes

0 commit comments

Comments
 (0)