From 268df87b6351e754442b43c01dd18792a36f370c Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 18:29:26 -0400 Subject: [PATCH] feat: add onHashProgress --- src/methods/upload.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/methods/upload.ts b/src/methods/upload.ts index 34ae73e..a2b55ff 100644 --- a/src/methods/upload.ts +++ b/src/methods/upload.ts @@ -1,4 +1,4 @@ -import { AxiosProgressEvent } from "axios"; +import {AxiosProgressEvent} from "axios"; import { DetailedError, HttpRequest, @@ -43,6 +43,11 @@ const PORTAL_FILE_FIELD_NAME = "file"; const TUS_ENDPOINT = "/s5/upload/tus"; +export interface HashProgressEvent { + bytes: number; + total: number; +} + /** * Custom upload options. * @@ -59,6 +64,7 @@ export type CustomUploadOptions = BaseCustomOptions & { largeFileSize?: number; retryDelays?: number[]; onUploadProgress?: (progressEvent: AxiosProgressEvent) => void; + onHashProgress?: (progressEvent: HashProgressEvent) => void; }; export const DEFAULT_UPLOAD_OPTIONS = { @@ -238,6 +244,10 @@ export async function getTusOptions( const chunk = file.slice(position, position + chunkSize); hasher.update(new Uint8Array(await chunk.arrayBuffer())); position += chunkSize; + customOptions.onHashProgress?.({ + bytes: position, + total: file.size, + }) } const b3hash = hasher.digest();