IArchiveFileEntry in Aspose Zip could contain many more methods

In this piece of code, we get each entry of a Zip file and we extract it:

public void unzip(String outputPath) throws IOException {
        // Gets the outputDir as a File and ensures that it exists
        File outputDir = LwHelpers.ensureAndGetDir(outputPath);
        // Opens the archive and iterates the archive's entries
        try (IArchive archive = getArchive()) {
            archive.getFileEntries().forEach(entry -> {
                // Gets the desired output path for the entry
                Path entryOutputPath = Path.of(outputDir.toURI()).resolve(entry.getName());
                // Ensures the parent folder exsits
                LwHelpers.ensureAndGetDir(entryOutputPath.getParent().toString());
                // Extracts the folder
                entry.extract(entryOutputPath.toAbsolutePath().toString());
            });
        } finally {
            zipInputStream.close();
        }
    }

This is throwing an expection, because there is a folder entry in the zip, that gets extracted as an empty file instead. When a child entry is extracted, instead of the empty folder an empty file is found, by throwing an error.

My solution would be using the “isDirectory” method, but I noticed that that is not available in the superclass. The problem here is that the Archive could be (e.g.) also a SevenZip archive, so I cannot cast it to just ArchiveEntry

It seems I could solve it by checking if the last char was a ‘/’ and be able to distinguish if it were a folder or not. Still, I am not sure if it works for each type of compressed archive and having all the common methods declared in the abstract class would be good

Hello @mrossi,
due to its very nature, getFileEntries() must not return directory entries. We will filter them out for ZIP archive and review all of the IArchive implementers.

Thank you for the answer. In case you make these changes and ignore directory entries, what happens if a zip has an empty directory entry? Would that empty directory be skipped?

Yes, the empty directory would be skipped as other directories.

In case I wanted both files and directories, by still being able to differentiate between directories and files, how could I do after your change?

No, you’ll need to cast the archive to certain type, e. g. Archive and check its entry IsDirectory property (isDirectory() method in Java).

In this moment I have some methods “unified” for the different compression types (zip, 7zip, tar, …), by using the IArchive class.

In case of that change, I would need to write specific code for each of them. Why wouldn’t it be possible for the abstract class to already have the functionality of readin gdirectory entries?

Do you want something similar to IArchiveFileEntry interface, say IArchiveDirectoryEntry and getDirectoryEntries method returning collection of IArchiveDirectoryEntry?

I think in this case, I would like a method “getEntries” that returns both file and directory entries. Then the entries should have a way to distinguish between directories and files for sure

We need to think this over. Though I understand your need, the idea seems intricate to be compatible with the current classes and interfaces. There won’t be any changes in the upcoming March release, may be in the next one.