|
@@ -1,21 +1,5 @@
|
|
|
-import { convertBytesToHumanReadable } from "@/next/file";
|
|
|
-import log from "@/next/log";
|
|
|
import { ElectronFile } from "@/next/types/file";
|
|
|
|
|
|
-export async function getUint8ArrayView(
|
|
|
- file: Blob | ElectronFile,
|
|
|
-): Promise<Uint8Array> {
|
|
|
- try {
|
|
|
- return new Uint8Array(await file.arrayBuffer());
|
|
|
- } catch (e) {
|
|
|
- log.error(
|
|
|
- `Failed to read file blob of size ${convertBytesToHumanReadable(file.size)}`,
|
|
|
- e,
|
|
|
- );
|
|
|
- throw e;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
export function getFileStream(file: File, chunkSize: number) {
|
|
|
const fileChunkReader = fileChunkReaderMaker(file, chunkSize);
|
|
|
|
|
@@ -36,6 +20,16 @@ export function getFileStream(file: File, chunkSize: number) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+async function* fileChunkReaderMaker(file: File, chunkSize: number) {
|
|
|
+ let offset = 0;
|
|
|
+ while (offset < file.size) {
|
|
|
+ const chunk = file.slice(offset, chunkSize + offset);
|
|
|
+ yield new Uint8Array(await chunk.arrayBuffer());
|
|
|
+ offset += chunkSize;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
export async function getElectronFileStream(
|
|
|
file: ElectronFile,
|
|
|
chunkSize: number,
|
|
@@ -46,14 +40,3 @@ export async function getElectronFileStream(
|
|
|
chunkCount,
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
-async function* fileChunkReaderMaker(file: File, chunkSize: number) {
|
|
|
- let offset = 0;
|
|
|
- while (offset < file.size) {
|
|
|
- const blob = file.slice(offset, chunkSize + offset);
|
|
|
- const fileChunk = await getUint8ArrayView(blob);
|
|
|
- yield fileChunk;
|
|
|
- offset += chunkSize;
|
|
|
- }
|
|
|
- return null;
|
|
|
-}
|