sonikdrive-file-upload
Version:
Chunked file using upload session URLs
27 lines (26 loc) • 1.14 kB
JavaScript
"use strict";
// import { Readable } from 'stream';
// import * as fs from 'fs/promises';
// export type SupportedFileInput = File | Blob | Buffer | Readable | string;
// export async function normalizeFileInput(input: SupportedFileInput): Promise<Buffer | Blob> {
// if (typeof File !== 'undefined' && input instanceof File) return input;
// if (typeof Blob !== 'undefined' && input instanceof Blob) return input;
// if (Buffer.isBuffer(input)) return input;
// if (typeof input === 'string') {
// try {
// await fs.access(input); // Check if file exists
// return await fs.readFile(input); // Read file as Buffer
// } catch {
// return Buffer.from(input, 'base64'); // Treat as base64 string
// }
// }
// if (isReadableStream(input)) {
// const chunks: Buffer[] = [];
// for await (const chunk of input) chunks.push(Buffer.from(chunk));
// return Buffer.concat(chunks);
// }
// throw new Error('Unsupported file input type.');
// }
// function isReadableStream(obj: any): obj is Readable {
// return obj && typeof obj.pipe === 'function' && typeof obj._read === 'function';
// }