CategoriesUncategorized

Convert Bytes to MB/KB/GB/TB

    bytesToSize(bytes) {
      const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
      const i = Number(Math.floor(Math.log(bytes) / Math.log(1024)));
      if (bytes === 0) return '0 Byte';
      return `${Math.round(bytes / (1024 ** i), 2)} ${sizes[i]}`;
    },

Leave a Reply

Your email address will not be published. Required fields are marked *