Skip to content

Conversation

@SSimco
Copy link
Contributor

@SSimco SSimco commented Aug 30, 2025

The purpose of this change is to allow reading from files that cannot be opened directly from C++ code.

For example, on Android, if you want to open files that are not located in the app's internal storage, you must use SAF.
With SAF, you obtain a file descriptor, which can then be passed to C++ for reading.

Here's an example:

#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream_buffer.hpp>
#include <zarchive/zarchivereader.h>
#include <istream>

using namespace boost::iostreams;

std::string fileUri = "content://com.android.externalstorage.documents/...";

// Call Java code to open the file using SAF and return a raw file descriptor
int fd = openContentUri(fileUri);

stream_buffer<file_descriptor_source> sb(fd, close_handle);
auto zar = ZArchiveReader::OpenFromStream(std::make_unique<std::istream>(&sb));
// ...
delete zar;

@Exzap Exzap merged commit 965b66c into Exzap:master Aug 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants