Menu

#703 '7z list' order

open
nobody
None
5
5 days ago
5 days ago
Zhai Can
No

Regarding the listing order, .7z formats differ with other archive formats (e.g. tar, zip, rar etc.). I have files in this structure:

❯ tree d1 d2
d1
├── d12
│   └── file
└── file
d2
└── file

Compress it now using 7z a a.7z d1 d2, then list it via 7z l a.7z, one can see output:

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2026-07-31 15:53:08 D....            0            0  d1
2026-07-31 15:53:10 D....            0            0  d1/d12
2026-07-31 15:52:56 D....            0            0  d2
2026-07-31 15:53:10 ....A            0            0  d1/d12/file
2026-07-26 03:02:10 ....A            0            0  d1/file
2026-07-26 03:02:14 ....A            0            0  d2/file
------------------- ----- ------------ ------------  ------------------------
2026-07-31 15:53:10                  0            0  3 files, 3 folders

Seems 7z groups directory together. As a comparison, other archive formats add files in a DFS order:

❯ zip -Z store -r a.zip d1 d2; 7z l a.zip
...

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2026-07-31 15:53:08 D....            0            0  d1
2026-07-26 03:02:10 .....            0            0  d1/file
2026-07-31 15:53:10 D....            0            0  d1/d12
2026-07-31 15:53:10 .....            0            0  d1/d12/file
2026-07-31 15:52:56 D....            0            0  d2
2026-07-26 03:02:14 .....            0            0  d2/file
------------------- ----- ------------ ------------  ------------------------
2026-07-31 15:53:10                  0            0  3 files, 3 folders

This effectively causes yazi bug: https://github.com/sxyazi/yazi/issues/4162 so I'm just wondering - is there any specific reason 7z adds files in this special order?

This is not necessarily a bug though however due to yazi's design philosophy they don't want to handle 7z's case on their side. Due to the fact I've observed that 7z l reads and stages all the archive entries in memory and then outputs them all at once, it it reasonable to add a cli switch for 7z l to "sort" them before output?

Discussion

  • Zhai Can

    Zhai Can - 5 days ago

    A copy from yazi's author as a reference, stating the idea -

    Yeah that's exactly why previewers (not just archive.lua), are designed to do as little data processing as possible. For performance, doing less may be better than using a smarter algorithm.

    My idea hasn't changed much: ask 7-Zip to add an option to 7z l:

    • Non-mandatory: Prefer outputting the list sequentially rather than interleaved.
    • Mandatory: Sort the list before outputting it. As you said, if 7z already outputs everything at once, it probably already has all the info needed to sort it.
    • Or a combination of both: Output lists as-is if they're already sequential, otherwise sort them first.

    Either way, it would be an improvement over the current situation.

    The idea is that 7z has more info about the archive and may have more room for optimization than post-processing everything in Yazi (or a wrapper, which basically does the same). This wouldn't just benefit Yazi, showing an ordered file list could also be useful to others, since it would make the list clearer and easier to read.

    Thanks in advance!

     
  • Igor Pavlov

    Igor Pavlov - 5 days ago

    7z stores files in "solid" groups for better compression.
    Directory entry is just metadata without data. So directory entries are stored outside of file groups.

     

Log in to post a comment.