Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipArchive::addFile needs variant with std::wstring #226

Open
jjYBdx4IL opened this issue May 4, 2024 · 3 comments
Open

ZipArchive::addFile needs variant with std::wstring #226

jjYBdx4IL opened this issue May 4, 2024 · 3 comments

Comments

@jjYBdx4IL
Copy link

Otherwise boost (and likely std::filesystem::path) users need to convert wstring to multibyte before libzippp internally converts it back to wstring. :)

@ctabin
Copy link
Owner

ctabin commented May 8, 2024

Hi @jjYBdx4IL,
Thanks for the suggestion, it seems to be a good idea.
Do you mind making a PR ?

@jjYBdx4IL
Copy link
Author

Looking into it

@jjYBdx4IL
Copy link
Author

jjYBdx4IL commented May 8, 2024

Here is what I currently do on Windows:

    ZipArchive zf(Util::Win32::conv2mbcs(_zipFile.wstring()));
    BOOST_CHECK(zf.open(ZipArchive::Write));

    // no wstring support, doesn't work:
    //BOOST_CHECK(!zf.addFile(textFile.lexically_relative(rootPath).generic_wstring(), textFile.generic_wstring()));

    // doesn't work - resulting data is garbage:
    //boost::iostreams::mapped_file_source src(textFile);
    //BOOST_CHECK(zf.addData(Util::Win32::conv2mbcs(textFile.lexically_relative(rootPath).generic_wstring()), src.data(), src.size()));
    //src.close();

    BOOST_CHECK(zf.addFile(
        Util::Win32::conv2mbcs(textFile.lexically_relative(rootPath).generic_wstring()),
        Util::Win32::conv2mbcs(textFile.generic_wstring())));

The utility function is essentially just the winapi WideCharToMultiByte function.

I looked at the code and I also tried some other zip libs and they all show the same behavior. It seems to boil down to libzip not supporting UTF-16 on Windows - or only via UTF-8. So I'd say it's an upstream issue. We could hack the Windows conversion function into libzippp, but that would just mask the upstream issue.

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

No branches or pull requests

2 participants