Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: file size unit #1320

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/mako/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub fn write_stats(stats: &StatsJsonMap, compiler: &Compiler) {

// 文件大小转换
pub fn human_readable_size(size: u64) -> String {
let units = ["kB", "mB", "gB"];
let units = ["kB", "MB", "GB"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥 kB 不一起大写了

Copy link
Contributor Author

@hualigushi hualigushi Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

浏览器 network 显示的是 kB MB , webpack 也是这样显示的
k 是 kilo,M 是 mega,G 是 giga

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kB 和 KB 是用来表示计算机数据存储容量的单位,它们的区别在于所代表的容量大小不同:

  1. kB (kilobyte):

    • 在计算机科学中,1 kB 通常等于 1024 字节 (bytes)。这是因为计算机是基于二进制系统的,1024 是 2 的 10 次方。
    • 有时在某些上下文中,特别是国际标准组织(ISO)推荐的使用下,1 kB 也可以表示 1000 字节。为了避免混淆,这种情况下更常使用 "kB" 表示 1000 字节,而使用 "KiB"(kibibyte)表示 1024 字节。
  2. KB (Kilobyte):

    • 通常用来表示 1000 字节,这是根据国际单位制(SI)前缀定义的。SI 前缀 “Kilo” 表示 1000。
    • 然而在很多实际应用中,KB 和 kB 都常被混用来表示 1024 字节,特别是在传统计算机领域。

为了更清晰的区分,国际电工委员会(IEC)推荐使用二进制前缀:

  • KiB (kibibyte): 1 KiB = 1024 字节 (2¹⁰ bytes)
  • KB (kilobyte): 1 KB = 1000 字节 (10³ bytes)

总结:

  • kB 或 KiB 通常用于表示 1024 字节。
  • KB 通常用于表示 1000 字节,但在某些情况下,可能也表示 1024 字节。

在使用过程中,了解上下文和具体用法是很重要的,以避免混淆。

// 把 B 转为 KB
let mut size = (size as f64) / 1000.0;
let mut i = 0;
Expand Down
Loading