jupyterlab / jupyterlab

JupyterLab computational environment.
https://jupyterlab.readthedocs.io/
Other
14.12k stars 3.34k forks source link

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

Open msanchezst opened 5 months ago

msanchezst commented 5 months ago

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.

welcome[bot] commented 5 months ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
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! :wave:
Welcome to the Jupyter community! :tada:

krassowski commented 5 months ago

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

https://github.com/jupyterlab/jupyterlab/blob/b3f0b44b1136e50b757ad23db4b02d44ccd80740/packages/filebrowser/src/listing.ts#L2695-L2700

Using this function:

https://github.com/jupyterlab/jupyterlab/blob/b3f0b44b1136e50b757ad23db4b02d44ccd80740/packages/filebrowser/src/listing.ts#L3007-L3027

krassowski commented 5 months ago

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 commented 5 months ago

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

https://github.com/jupyterlab/jupyterlab/blob/b3f0b44b1136e50b757ad23db4b02d44ccd80740/packages/filebrowser/src/listing.ts#L2695-L2700

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:

https://github.com/jupyterlab/jupyterlab/blob/b3f0b44b1136e50b757ad23db4b02d44ccd80740/packages/filebrowser/src/listing.ts#L3020

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?