handle type errors

pull/134/head
Alex Kern 1 year ago
parent f8d35c8e6d
commit 102053ea64
No known key found for this signature in database
GPG Key ID: EF051FACCACBEE25

@ -50,7 +50,7 @@ function cleanErrorMessage(errorMessage: string): string {
type DownloadFileStream = { type DownloadFileStream = {
name: string name: string
size: number size: number
stream: () => ReadableStream stream: () => ReadableStream<Uint8Array>
} }
export async function streamDownloadSingleFile( export async function streamDownloadSingleFile(
@ -82,7 +82,7 @@ export function streamDownloadMultipleFiles(
const readableZipStream = createZipStream({ const readableZipStream = createZipStream({
start(ctrl) { start(ctrl) {
for (const file of files) { for (const file of files) {
ctrl.enqueue(file) ctrl.enqueue(file as unknown as ArrayBufferView)
} }
ctrl.close() ctrl.close()
}, },
@ -216,25 +216,30 @@ export default function Downloader({
}, []) }, [])
const handleStartDownload = useCallback(() => { const handleStartDownload = useCallback(() => {
if (!filesInfo || !dataConnection) return
setDownloading(true) setDownloading(true)
const fileStreamByPath: Record< const fileStreamByPath: Record<
string, string,
{ {
stream: ReadableStream stream: ReadableStream<Uint8Array>
enqueue: (chunk: any) => void enqueue: (chunk: Uint8Array) => void
close: () => void close: () => void
} }
> = {} > = {}
const fileStreams = filesInfo.map((info) => { const fileStreams = filesInfo.map((info) => {
let enqueue: ((chunk: any) => void) | null = null let enqueue: ((chunk: Uint8Array) => void) | null = null
let close: (() => void) | null = null let close: (() => void) | null = null
const stream = new ReadableStream({ const stream = new ReadableStream<Uint8Array>({
start(ctrl) { start(ctrl) {
enqueue = (chunk: any) => ctrl.enqueue(chunk) enqueue = (chunk: Uint8Array) => ctrl.enqueue(chunk)
close = () => ctrl.close() close = () => ctrl.close()
}, },
}) })
if (!enqueue || !close) {
throw new Error('Failed to initialize stream controllers')
}
fileStreamByPath[info.fileName] = { fileStreamByPath[info.fileName] = {
stream, stream,
enqueue, enqueue,

Loading…
Cancel
Save