mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-28 23:52:47 +00:00
Some checks failed
Deploy image by kubeconfig / build-fastgpt-docs-images (push) Has been cancelled
Deploy image to vercel / deploy-production (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (push) Has been cancelled
Deploy image by kubeconfig / update-docs-image (push) Has been cancelled
Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
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();
|
|
};
|