-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.ts
More file actions
25 lines (24 loc) · 789 Bytes
/
utils.ts
File metadata and controls
25 lines (24 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { AsyncBuffer, asyncBufferFromUrl, cachedAsyncBuffer } from 'hyparquet'
import { AsyncBufferFrom } from './types.js'
export function fromToAsyncBuffer(from: AsyncBufferFrom, cache?: Map<string, Promise<AsyncBuffer>>): Promise<AsyncBuffer> {
if ('url' in from) {
// Cached asyncBuffer for urls only
const key = JSON.stringify(from)
if (cache) {
const cached = cache.get(key)
if (cached) return cached
}
const asyncBuffer = asyncBufferFromUrl(from).then(cachedAsyncBuffer)
if (cache) {
cache.set(key, asyncBuffer)
}
return asyncBuffer
} else {
return Promise.resolve({
byteLength: from.file.size,
slice(start: number, end?: number) {
return from.file.slice(start, end).arrayBuffer()
},
})
}
}