borisbrodski / sevenzipjbinding

7-Zip-JBinding
http://sevenzipjbind.sourceforge.net/
Other
176 stars 50 forks source link

Archive compression empty directory #64

Closed BTYHunter closed 7 months ago

BTYHunter commented 1 year ago

Is supprot compress empty directory?

Item[] items = new Item[6];

items[0] = new Item("info.txt", "This is the info");

byte[] content = new byte[100];
new Random().nextBytes(content);
items[1] = new Item("random-100-bytes.dump", content);

// dir1 doesn't have separate archive item
items[2] = new Item("dir1" + File.separator + "file1.txt",
        "This file located in a directory 'dir'");

// dir2 does have separate archive item
items[3] = new Item("dir2" + File.separator, (byte[]) null);
items[4] = new Item("dir2" + File.separator + "file2.txt",
        "This file located in a directory 'dir'");
items[5] = new Item("dir3" + File.separator, "");  // this is empty directory

exception is,

7z-Error occurs:
HRESULT: 0x80070057 (Invalid argument). Error creating 'zip' archive with 6 items
    at net.sf.sevenzipjbinding.impl.OutArchiveImpl.nativeUpdateItems(Native Method)
    at net.sf.sevenzipjbinding.impl.OutArchiveImpl.doUpdateItems(OutArchiveImpl.java:141)
    at net.sf.sevenzipjbinding.impl.OutArchiveImpl.createArchive(OutArchiveImpl.java:150)
    at net.sf.sevenzipjbinding.impl.OutArchiveZipImpl.createArchive(OutArchiveZipImpl.java:29)
    at demo.CompressNonGenericZip.compress(CompressNonGenericZip.java:94)
    at demo.CompressNonGenericZip.main(CompressNonGenericZip.java:73)
+------ SevenZipException with multiple 'cause by' exceptions. Stacktraces for all involved exceptions:
+-- The SevenZipException itself with first thrown 'cause by' exception (first cause): 
| HRESULT: 0x80070057 (Invalid argument). Error creating 'zip' archive with 6 items
|   at net.sf.sevenzipjbinding.impl.OutArchiveImpl.nativeUpdateItems(Native Method)
F   at net.sf.sevenzipjbinding.impl.OutArchiveImpl.doUpdateItems(OutArchiveImpl.java:141)
I   at net.sf.sevenzipjbinding.impl.OutArchiveImpl.createArchive(OutArchiveImpl.java:150)
R   at net.sf.sevenzipjbinding.impl.OutArchiveZipImpl.createArchive(OutArchiveZipImpl.java:29)
S   at demo.CompressNonGenericZip.compress(CompressNonGenericZip.java:94)
T   at demo.CompressNonGenericZip.main(CompressNonGenericZip.java:73)
+------ End of stacktrace of SevenZipException with multiple 'cause by' exceptions
borisbrodski commented 1 year ago

Currently not. Let this issue open and I will see, if it is possible with the new version of 7-Zip.

BTYHunter commented 12 months ago

This works!

// items[5] = new Item("dir3" + File.separator, "");  // this is empty directory
items[5] = new Item("dir3" + File.separator, (byte[]) null);

Can we close this issuse?