omicronapps / 7-Zip-JBinding-4Android

Android Java wrapper for 7z archiver engine
GNU Lesser General Public License v2.1
122 stars 25 forks source link

Compatibility of the library with SAF? #9

Open fiasko131 opened 3 years ago

fiasko131 commented 3 years ago

Is there a way to use this library with an Outputstream obtained by SAF in android.

For example to compress on an external memory card I cannot use:

raf = new RandomAccessFile(zipPath, "rw");
outArchiveZip = SevenZip.openOutArchiveZip();
outArchiveZip.setLevel(level);
outArchiveZip.createArchive(new RandomAccessFileOutStream(raf),//
items.length, new CallBackZip());

RandomAccessFile is not compatible with SAF.

Of course I can compress on the internal storage and then copy , but obviously that's not ideal.

Thank you.

omicronapps commented 3 years ago

I'm afraid sevenzipjbinding does not include an OutStream implementation that uses OutputStream.

You will need to create such a class yourself by implementing the IOutStream interface in sevenzipjbinding.

For reference you can look at the following two existing OutStream implementations provided with sevenzipjbinding:

fiasko131 commented 3 years ago

Okay, I'll see if I can implement it later and come back later to share.

For the moment, in the case of a creation, I keep the Zip4j library which allows to work with an outputstream.

RobbWatershed commented 3 years ago

@fiasko131 I've implemented a perfectly functional Helper/wrapper for this lib that works with SAF (API21+)

https://github.com/avluis/Hentoid/blob/dcb208eabbfc134b20d68c996cce89989179655e/app/src/main/java/me/devsaki/hentoid/util/ArchiveHelper.java

It's been tested by many users with different devices 👍

However it only reads archives. Creating archives is not a use case for my app, but maybe you can get inspiration from what I did...

asthagarg2428 commented 2 years ago

@fiasko131 Any luck with SAF in extraction & compression?