mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
16 lines
483 B
TypeScript
16 lines
483 B
TypeScript
import { detect } from 'jschardet';
|
|
|
|
export const formatFileSize = (bytes: number): string => {
|
|
if (bytes === 0) return '0 B';
|
|
|
|
const k = 1024;
|
|
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
};
|
|
|
|
export const detectFileEncoding = (buffer: Buffer) => {
|
|
return detect(buffer.slice(0, 200))?.encoding?.toLocaleLowerCase();
|
|
};
|