[#115] Implement Binary File Attachments (#116)

This commit is contained in:
Knut Ahlers 2023-10-02 21:52:24 +02:00 committed by GitHub
parent a098395daf
commit c5124731f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 330 additions and 31 deletions

21
src/helpers.js Normal file
View file

@ -0,0 +1,21 @@
/**
* Converts number of bytes into human format (524288 -> "512.0 KiB")
* @param {Number} bytes Byte amount to convert into human readable format
* @returns String
*/
function bytesToHuman(bytes) {
for (const t of [
{ thresh: 1024 * 1024, unit: 'MiB' },
{ thresh: 1024, unit: 'KiB' },
]) {
if (bytes > t.thresh) {
return `${(bytes / t.thresh).toFixed(1)} ${t.unit}`
}
}
return `${bytes} B`
}
export {
bytesToHuman,
}