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

Extract have something wrong #223

Open
EunChae1110 opened this issue Jan 9, 2024 · 4 comments
Open

Extract have something wrong #223

EunChae1110 opened this issue Jan 9, 2024 · 4 comments

Comments

@EunChae1110
Copy link

I use libzippp to make extract. This is the code:

void ExtractZip(std::string path)
{
	ZipArchive zip(path);
	zip.open(ZipArchive::ReadOnly);
	std::vector<ZipEntry> entries = zip.getEntries();
	std::vector<ZipEntry>::iterator it;
	path = "./"+path.substr(0, path.find(".zip"));
	std::filesystem::create_directory(path);
	for (it = entries.begin(); it != entries.end(); ++it)
	{
		ZipEntry entry = *it;
		if (entry.isDirectory())
		{
			std::filesystem::create_directories(path+"\\"+entry.getName());
		}
		std::ofstream unzippedFile(path + "\\"+entry.getName());
		entry.readContent(unzippedFile);
		unzippedFile.close();
	}
	zip.close();
}

However, when I checked the file after extracted, the file destroyed.
Original file:
image
After extract:
image

@ctabin
Copy link
Owner

ctabin commented Jan 11, 2024

Hi @EunChae1110,
What about the zip ? If you extract the file with zip is it correct ?
Did you try with another extraction method ?
Can you provide a full test case ?
Thanks.

@EunChae1110
Copy link
Author

Because of my file is large. I saw your document that is using readContent. I used WinRAR to archive the zip

@EunChae1110
Copy link
Author

Here is any extraction method in libzippp?

@Jcdoliner
Copy link

Might be an old issue but if anybody still has trouble with this:

I had the same issue as you. you should put the mode of your ofstream to std::ios::binary. It can be something like this:
std::ofstream desFile((filename),std::ios::binary);
This causes the output file stream to open in binary mode thus appending the correct character sequence.

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

3 participants