Coder Social home page Coder Social logo

Comments (5)

rikyoz avatar rikyoz commented on August 24, 2024

I've been trying to compress / decompress a vector of bytes by feeding it into a BitOutputArchive or a BitInputArchive respectively.

Usually, you don't want to directly use BitOutputArchive/BitInputArchive, and should use BitArchiveWriter/BitArchiveReader instead. This is because the former classes need a separate BitAbstractArchiveCreator/BitAbstractArchiveHandler instance, while the writer and reader classes already implement these abstractions.

This was rejected as unpermitted operation.

What is the exact error message and error code thrown by bit7z?

Should I use BitMemoryCompressor?

BitMemCompressor internally uses BitOutputArchive, so it will likely behave exactly as this latter. In general, it is useful when you want to create multiple archives from memory data using the same compression settings/callbacks. In all other cases, e.g., creating only one archive, BitArchiveWriter is the standard choice.

The same applies to the BitMemExtractor vs BitArchiveReader.

from bit7z.

a1880 avatar a1880 commented on August 24, 2024

Thank you for your time and your gracious help.

I tried the following:

bit7z::Bit7zLibrary lib{ LR"(C:\util\7z.dll)" };

void compress(const std::vector<bit7z::byte_t>& data, std::vector<bit7z::byte_t>& compressed)
{
	try
	{
		bit7z::BitArchiveWriter writer(lib, bit7z::BitFormat::GZip);
		writer.compressTo(compressed);

		std::cout << "Compression succeeded!" << std::endl;
	}
	catch (bit7z::BitException ex)
	{
		std::cout << "Compression failed! " << ex.what() << std::endl;
	}
}

This throws an exception in compressTo().
Within writer.compressTo(), the exception is thrown in compressOut().
Variable outMemStream might be the culprit.
Result of outArc->UpdateItems() is E_INVALIDARG One or more arguments are invalid.

from bit7z.

rikyoz avatar rikyoz commented on August 24, 2024

The problem is that, in your function, you're not adding any data to the archive (e.g., using writer.addFile(data, "filename")).
7-Zip doesn't support creating empty GZip archives, hence your error.
Also, the GZip format itself doesn't allow adding more than one file, so only one file/buffer of data can be added to the archive; otherwise, a similar error will be thrown by the compressTo method.

from bit7z.

a1880 avatar a1880 commented on August 24, 2024

That makes sense. Thank you again!

I've now managed to make it work.
Please find my code attached as example usage of bit7z.

BZip7.zip

from bit7z.

rikyoz avatar rikyoz commented on August 24, 2024

That makes sense. Thank you again!

No problem!

As a side note, I definitely need to improve the error message and code in such cases, as 7-Zip is really not good at reporting the causes of such errors, unfortunately.

Please find my code attached as example usage of bit7z.

I took a look at your code and it seems fine to me.
Just a note: BitArchiveReader can directly extract to a buffer, so the decompression function can be simplified as follows

void BZip7::decompress(const std::vector<bit7z::byte_t>& data, std::vector<bit7z::byte_t>& decompressed) const
{
	try
	{
		bit7z::BitArchiveReader reader(lib, data, bit7z::BitFormat::GZip);
		reader.extractTo(decompressed);
		std::cout << "Decompression succeeded!" << std::endl;
	}
	catch (bit7z::BitException ex)
	{
		std::cout << "Decompression failed! " << ex.what() << std::endl;
	}
}

from bit7z.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.