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

File size display in file browser should use correct units #16205

Open
msanchezst opened this issue Apr 19, 2024 · 4 comments
Open

File size display in file browser should use correct units #16205

msanchezst opened this issue Apr 19, 2024 · 4 comments

Comments

@msanchezst
Copy link

Problem

We have noticed that the file size displayed in the Jupyterlab file browser appears to be using an incorrect unit. The file sizes are reported in MiB but the displayed units are MB,GB, and so on. This is confusing as the actual size is not accurately represented.

Proposed Solution

I would recommend updating the file browser to display the file sizes using the correct units (MiB) to match the actual file sizes reported by the OS.

Screenshot

In the screenshot above, the units displayed in the File Explorer should be MiB

Additional context

Has this issue been evaluated in the past and decided to report the file sizes in this way? If so, I'm curious to understand the reasoning behind that decision.

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Apr 19, 2024
Copy link

welcome bot commented Apr 19, 2024

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@krassowski
Copy link
Member

Quick look: I think that the file manager in jupyter-server by default returns size in bytes, based on this code referencing st_size which normally is in bytes.

Then on frontend this is formatted here

const fileSizeText = Private.formatFileSize(model.size, 1, 1024);
fileSize.textContent = fileSizeText;
hoverText += trans.__(
'\nSize: %1',
Private.formatFileSize(model.size, 1, 1024)
);

Using this function:

/**
* Format bytes to human readable string.
*/
export function formatFileSize(
bytes: number,
decimalPoint: number,
k: number
): string {
// https://www.codexworld.com/how-to/convert-file-size-bytes-kb-mb-gb-javascript/
if (bytes === 0) {
return '0 B';
}
const dm = decimalPoint || 2;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
if (i >= 0 && i < sizes.length) {
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
} else {
return String(bytes);
}
}

@krassowski
Copy link
Member

Does it make more sense to show MiB vs MB? What do most file browsers show? Real-estate-wise MB is shorter. Should it be configurable?

@msanchezst
Copy link
Author

msanchezst commented Apr 22, 2024

@krassowski thank you for your quick response! Based on this:

const fileSizeText = Private.formatFileSize(model.size, 1, 1024);
fileSize.textContent = fileSizeText;
hoverText += trans.__(
'\nSize: %1',
Private.formatFileSize(model.size, 1, 1024)
);

it looks to me that because of the value of 1024 set in the formatFileSize, the formatted file size is converted to Bi Units (KiB,MiB,GiB), but the labels here are incorrect:

const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

As for what units to display, that's a good question. Mac and Windows file browsers typically use MB. Some Linux file browsers let you change the units. Technically, MiB might be more accurate, but I don't think there is a established standard here. Perhaps making this configurable would be the best approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants