ソースを参照

bye getUint8ArrayView

Manav Rathi 1 年間 前
コミット
fa0d1331a8

+ 1 - 2
web/apps/photos/src/services/detect-type.ts

@@ -7,7 +7,6 @@ import {
 import { lowercaseExtension } from "@/next/file";
 import { lowercaseExtension } from "@/next/file";
 import { CustomError } from "@ente/shared/error";
 import { CustomError } from "@ente/shared/error";
 import FileType from "file-type";
 import FileType from "file-type";
-import { getUint8ArrayView } from "./readerService";
 
 
 /**
 /**
  * Read the file's initial contents or use the file's name to detect its type.
  * Read the file's initial contents or use the file's name to detect its type.
@@ -89,7 +88,7 @@ export const detectFileTypeInfoFromChunk = async (
 const readInitialChunkOfFile = async (file: File) => {
 const readInitialChunkOfFile = async (file: File) => {
     const chunkSizeForTypeDetection = 4100;
     const chunkSizeForTypeDetection = 4100;
     const chunk = file.slice(0, chunkSizeForTypeDetection);
     const chunk = file.slice(0, chunkSizeForTypeDetection);
-    return await getUint8ArrayView(chunk);
+    return new Uint8Array(await chunk.arrayBuffer());
 };
 };
 
 
 const detectFileTypeFromBuffer = async (buffer: Uint8Array) => {
 const detectFileTypeFromBuffer = async (buffer: Uint8Array) => {

+ 10 - 27
web/apps/photos/src/services/readerService.ts

@@ -1,21 +1,5 @@
-import { convertBytesToHumanReadable } from "@/next/file";
-import log from "@/next/log";
 import { ElectronFile } from "@/next/types/file";
 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) {
 export function getFileStream(file: File, chunkSize: number) {
     const fileChunkReader = fileChunkReaderMaker(file, chunkSize);
     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(
 export async function getElectronFileStream(
     file: ElectronFile,
     file: ElectronFile,
     chunkSize: number,
     chunkSize: number,
@@ -46,14 +40,3 @@ export async function getElectronFileStream(
         chunkCount,
         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;
-}