Giter Site home page Giter Site logo

rikyoz / bit7z Goto Github PK

View Code? Open in Web Editor NEW
577.0 17.0 105.0 5.36 MB

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.

Home Page: https://rikyoz.github.io/bit7z

License: Mozilla Public License 2.0

C++ 95.68% CMake 4.32%
compression extraction 7z zip rar bzip2 gzip tar archives multi-volume-archives

bit7z's People

Contributors

anywhereyang avatar cjtallman avatar csabesz88 avatar dymok93 avatar gr3yknigh1 avatar kenkit avatar luosiyuan avatar michaelkle avatar rikyoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bit7z's Issues

[Feature Request]: mini head-only file for parsing tar packages

Feature description

I want a mini head-only for only parsing tar pacakges.

BECAUSE I need this functionality on a very edge device which need as small size of program as possible

Additional context

I don't need 7z, zip or anything else format, I just want tar packages can be load and read. not even need write it

Code of Conduct

Rename files and folders

Is there a method to rename files and folders inside the compressed file?
If it doesn't exist, can it be implemented?

Fabrizio.

How to extract entire content of the existing 7z file to memory?

I found the codes to extract a file by an index.
bit7z::Bit7zLibrary lib(L"7z.dll");
bit7z::BitExtractor extractor(lib, bit7z::BitFormat::SevenZip);
std::vector out_buffer;
unsigned index = 0;
extractor.extract(L"test.7z", out_buffer, index);

So how to extract all the files in the archive and it's buffer to a
std::map<std::wstring, std::vector >?

Large Memory Pages support

7-Zip DLLs supports using Large Memory Pages as a speed optimization.

It would be nice if we could request this to be used when possible if it already isn't used by default.

The 7-Zip API to call is SetLargePageMode.

[Feature Request]: 7zip v21.06 official binaries do not contain dynamic libraries to be linked on Linux and macOS. what now?

Feature description

Thank you again for working on this very interesting project. I do not know however if this my question is not out of scope. But if I understand well, the bit7z library links dynamically to 7z.dll, 7z.so or 7z.dylib, depending on the platform. But as I noticed in the official downloads for the latest version of 7Zip (21.06) https://www.7-zip.org/download.html the versions for Linux and macOS contain only single-file console-only executables but no dynamic libraries. So there is nothing to link to. How can this problem be solved? Does this require the user to build 7zip dynamic library on their own? If so, couldn't bit7z somehow simplify the process?

Kudos to you!

Additional context

No response

Code of Conduct

How can i cancel a long operation?

I would like to write a backup program but I need to allow the user to cancel a compression / decompression / verification operation.
How can I do?

Also, I'd like to ask if the library is Thread-Safe.

Thanks for the help, Fabrizio.

[Feature Request]: dual licensing model in consideration?

Feature description

Aren't there any plans for dual licensing model of this library? So that there is a free-of-charge GPL version for non-commercial users and also a commercial version with which customers can pay the author and be allowed to link this library to their commercial closed-source software?

I think it could have lots of benefits:

  1. Stream of income for the author, which would be well deserved!
  2. Wider spread of bit7z usage.
  3. Benefits for commercial app developers who are (by my experience) struggling to find any really good archiving library on the market. I think they would be glad to pay for such a high quality library.

I do not know however if this is possible. I am no licensing expert. Doesn't it breach 7Zip license?

Additional context

No response

Code of Conduct

Support for callback when compress

This is a great project. It make using 7z.dll more simple!

I want to add compress function to my program and with your support, I made it. it is faster than zlib. However, I want to show the compress process in UI. Can you add callback API?

Thank you for all your work!

Instantiating bit7z::Bit7zLibrary as part of a class member

Describe the bug
Hi, I can't figure out how to instantiate Bit7zLibrary since the class is uncopiable and unassignable.

Expected behavior
I find this library similar to 7zip-cpp so I think it should be possible to load and initialize 7z.dll once in my class.

Environment details (put an x in all the boxes that apply):

  • bit7z version:

    • v2.0
    • v2.1
    • v3.0
  • 7-zip version:

    • v16.02
    • v16.03
    • v16.04
    • v18.01
    • v18.03
    • v18.05
  • MSVC version:

    • 2012
    • 2013
    • 2015
    • 2017
  • Windows version:

    • Windows Vista
    • Windows 8
    • Windows 8.1
    • Windows 10
  • Architecture:

    • x86
    • x86_64

Additional context
Add any other context about the problem here.

Hope to custom the directory system in the zip file

I used a zip.h and zip.cpp before. In its API, I can custom the directory system in the zip file.Here is its sample code.

HZIP hz = CreateZip("c:\\simple1.zip",0);
ZipAdd(hz,"1\\znsimple.bmp", "c:\\simple.bmp");
ZipAdd(hz,"znsimple.txt", "c:\\simple.txt");
CloseZip(hz);

and I can get the directory like this in the zip file.
-1
|--zmsimple.hpp
-znsimple.txt

If i compress file in the bit7z like this

std::vector<std::wstring> files = { L"1\\file1.jpg", L"file2.pdf" };
compressor.compressFiles(files, L"output_archive.zip");

the file1.jpg and the file2.pdf just lay in the zip file, I cann't specify the directory system in the zip file.

Thank you!

Extract rar4.x file fail

Describe the bug
I have try both RAR and RAR5, but fail to extract, it comes out with open file fail, any one can help?

The Callbacks should have a "void*" data in order to pass the "this" pointer in a class usage

Let me explain:
When I use the library in a class, I need to declare tha Callback procedure as "static" member.
With a static Callback procedure, I need to known from wich class object the call is made.
So I need the "this" pointer to be passed to the Callback.

Modification example:
Set Total callback: setTotalCallback( const TotalCallback &callback, void* lpData )
TotalCallback: void(uint64_t total_size, void* lpData)

[FR] Add error code member to BitException

Current implementation of BitException only contains textual error message. If I want to know the exact reason for the error the only way I see is comparing strings which is really inefficient, error-prone, and subject to breaking if error strings are changed in the future.

Looking at the code, in most of the places where exceptions are thrown there is either an error code from the OS GetLastError() API (such as ERROR_MOD_NOT_FOUND if library path is wrong, or ERROR_FILE_NOT_FOUND if archive path is wrong) or a HRESULT from 7-Zip code.

It would be nice if an error code was added to BitException, preferrably as a HRESULT.

Callback from file writing process

Is your feature request related to a problem? Please describe.
This library is great. However, when compressing lots of files (or large files) where the resulting archive is several hundred megabytes, there is a noticeable delay between compression progress reaching 100% (as calculated from the ProgressCallback) and when the BitCompressor.Compress method returns. My guess is that this is when the archive file is actually written to disk?

Describe the solution you'd like
Would it be possible to get another callback routine that describes this delay? e.g
void setWriteCallback( const ProgressCallback &callback )

can not find "lib/7zSDK/CPP/Windows/COM.cpp"

I want to build the staic lib accord to bit7z.pro, but I can not find the "lib/7zSDK/CPP/Windows/COM.cpp" file in 7zip SDK folder. There is a COM.h in "7zSDK/CPP/Windows" folder. Is this a mistake?

std::sort fails on BitArchiveInfo::items

Bit7z V3.1.3
Visual Studio 2019

Thought I'd sort the vector by filename:

bool sortfunc(BitArchiveItem a, BitArchiveItem b) { return a.name() < b.name(); }
...
BitArchiveInfo bai{ lib, path, BitFormat::Rar };
auto arc_items = bai.items();
std::sort(arc_items.begin(), arc_items.end(), sortfunc);

but got three of these utterly confusing compile errors:

1>E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\algorithm(7247,25): error C2280: 'bit7z::BitArchiveItem &bit7z::BitArchiveItem::operator =(const bit7z::BitArchiveItem &)': attempting to reference a deleted function
1>E:\proj\DarkThumbs2\DT_Bit7z\bit7z\include\bitarchiveitem.hpp(106): message : compiler has generated 'bit7z::BitArchiveItem::operator =' here
1>E:\proj\DarkThumbs2\DT_Bit7z\bit7z\include\bitarchiveitem.hpp(106,5): message : 'bit7z::BitArchiveItem &bit7z::BitArchiveItem::operator =(const bit7z::BitArchiveItem &)': function was implicitly deleted because 'bit7z::BitArchiveItem' has a data member 'bit7z::BitArchiveItem::mItemIndex' of const-qualified non-class type
1>E:\proj\DarkThumbs2\DT_Bit7z\bit7z\include\bitarchiveitem.hpp(97): message : see declaration of 'bit7z::BitArchiveItem::mItemIndex'
1>E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\algorithm(7369): message : see reference to function template instantiation '_BidIt *std::_Insertion_sort_unchecked<_RanIt,bool(__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)>(const _BidIt,const _BidIt,_Pr)' being compiled
1>        with
1>        [
1>            _BidIt=bit7z::BitArchiveItem *,
1>            _RanIt=bit7z::BitArchiveItem *,
1>            _Pr=bool (__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)
1>        ]
1>E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\algorithm(7399): message : see reference to function template instantiation 'void std::_Sort_unchecked<bit7z::BitArchiveItem*,bool(__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)>(_RanIt,_RanIt,__int64,_Pr)' being compiled
1>        with
1>        [
1>            _RanIt=bit7z::BitArchiveItem *,
1>            _Pr=bool (__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)
1>        ]
1>E:\proj\DarkThumbs2\DT_Bit7z\rar.cpp(31): message : see reference to function template instantiation 'void std::sort<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,bool(__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)>(const _RanIt,const _RanIt,_Pr)' being compiled
1>        with
1>        [
1>            _Ty=bit7z::BitArchiveItem,
1>            _RanIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<bit7z::BitArchiveItem>>>,
1>            _Pr=bool (__cdecl *)(bit7z::BitArchiveItem,bit7z::BitArchiveItem)
1>        ]

I get the same result even if I create a copy of the items() vector.

Any hints?
Thanks!

FileCallback should report filename with path

I am a new user of this library, hope I am not making fundamental misunderstanding of the lib.

I found that FileCallback only reports bare filename without path information in archive.

Can you make the callback report full path? Full path can be:

  • Full path of the extracted file on disk
  • Relative path as it appears in archive file

It's up to you to decide which is appropriate.

Total file size wrong when updating an archive

When I add a file or directory to an existing archive, the total size reported by the CallBack "TotalCallback" is wrong.

See the following code.
When I add the file "b.txt", the total size has an incorrect value (not equal to size of "b.txt").
The problem also occurs when I use "compressDirectory".

//Code ----------
#include "bitcompressor.hpp"
#include "bitexception.hpp"
#include "bitformat.hpp"

void TotalCallbackProc(uint64_t total_size);
void ProgressCallbackProc(uint64_t progress_size);

using namespace bit7z;

int main()
{
try {
Bit7zLibrary lib{ L"7z.dll" };

	BitCompressor compressor{ lib, BitFormat::SevenZip };
	compressor.setCompressionMethod(BitCompressionMethod::Lzma2);
	compressor.setCompressionLevel(BitCompressionLevel::NORMAL);

	compressor.setTotalCallback(TotalCallbackProc);
	compressor.setProgressCallback(ProgressCallbackProc);

	compressor.compressFile(L"C:\\a.txt", L"Output_archive.7z");
	compressor.setUpdateMode(true);
	compressor.compressFile(L"C:\\b.txt", L"Output_archive.7z");
}
catch (const BitException& ex) {
	//do something with ex.what()...
}

}

void TotalCallbackProc(uint64_t total_size)
{
//When compress "b.txt" the parameter total_size has a wrong value.
}

void ProgressCallbackProc(uint64_t progress_size)
{
}
// End Code ----------

[Feature Request]: Have the devs considered porting this over to Linux

Feature description

I really like this lib, unfortunately it's Windows exclusive. Are there plans to port this over to Linux (considering 7z now supports Linux officially?). If not, do you know of some viable alternatives (besides libarchive), or whether it's possible to use this lib somehow on a Linux machine?

Additional context

No response

Code of Conduct

Extract specific file to buffer

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
I can see that we can extract specific files by matching paths. However I'd like to extract a specific file to buffer.
I'm not sure how long it will take to implement this since my app needs this feature to extract webpages into a buffer.

Additional context (optional)
Something like this

extractor.extract( L"path/to/another/file.txt", buffer );

Code organization feedback

I hope you are safe.

I wanted to include bit7z in one of my projects as a git submodule.

What feels weird to me (kind of a brain dump after spending some time integrating it with my stuff):

  1. You have included 7zSDK in the lib subfolder of the project when those are actually source files, not prebuilt static library (or output static library) files.
  2. Your static library output is in the bin folder which is usually reserved for input or output executables for projects that have both. You might want to make bit7z DLL in the future, and then where will your bit7z.dll and corresponding import libraries go if you are putting static libraries in bin folder?
  3. Your OutDir and IntDir directives in bit7z.vcxproj file contain fully relative paths instead of specifying $(ProjectDir)bin\ or $(ProjectDir)build\.
  4. You are setting different output names for static libraries -- bit7z, bit7z_d, bit7z64, bit7z64_d. I am not sure whether that is required by some standard or not, but it just makes including them in another project harder because one has to manually specify all variations which is tedious and error prone. On the other hand, if the output name was the same, they could just put $(SolutionDir)bit7z\bin\$(PlaformTarget)\$(Configuration)\ to library path and bit7z.lib to additional libraries for all configurations and all platforms at once and be done with it.
  5. Defines for BIT7Z_AUTO_FORMAT and BIT7Z_REGEX_MATCHING should in my opinion be in the main bit7z include file. Rationale is that if I want BIT7Z_REGEX_MATCHING I need to put it in preprocessor directives in both bit7z project and in my own project to actually be able to use the methods. If it was defined in the header file (but commented out by default), I could just uncomment it before building and have it magically work in both projects. This is what other libraries usually do (i.e. the header files reflect build configuration).
  6. Your 7zSDK folder is a subfolder of your bit7z project. I personally prefer when 3rd party code resides outside of the project tree -- say a solution folder named bit7z with project folder bit7z and 7zSDK folder at same level as the project. What I usually do is:
+-MyAwesomeSolution
  +-3rdParty
    +-7zSDK
    +-bit7z
       +-include
       +-lib
         +-x64
           +-Debug
           +-Release
         +-x86
           +-Debug
           +-Release
    +-OpenSSL
    +-toml11
    +-readerwriterqueue
    +-rapidjson
    +-TurboJPEG
  +-MyAwesomeLibraryProject
  +-MyAwesomeExecutableProject

In this configuration everything is a separate project. In your case even 7zSDK could be a separate static library project. Rationale is that you don't need to rebuild projects which were not modified since the last build, which speeds up the build process.

Finally, you are not using precompiled headers (i.e. pch.h, pch.cpp). No idea why not, but they usually speed up the build considerably.

To summarize my suggestions:

  • Make a solution folder.
  • Move 7zSDK to solution level under 3rdParty folder (maybe you will have to add more 3rd party code later and putting it all under 3rdParty folder will reduce clutter).
  • Turn 7zSDK into a static library project.
  • Change OutDir to $(ProjectDir)lib\$(PlatformTarget)\$(Configuration)\.
  • Change IntDir to $(ProjectDir)obj\$(PlatformTarget)\$(Configuration)\.
  • Change TargetName back to $(ProjectName).
  • Add //#define BIT7Z_AUTO_FORMAT and //#define BIT7Z_REGEX_MATCHING to bit7z.hpp
  • Add precompiled headers to bit7z project.

I am sure some of those won't be practical and easy to implement but hopefully you will consider at least some of my suggestions.

Adding files to existing archive

I'm trying to add some files to an existing archive (zip file). However, I get error "Can't create archive file ".
My code for doing this is as follows
bit7z::BitCompressor compressor(lib, bit7z::BitFormat::Zip);
std::vector<std::wstring> rootFiles = Utilities::getAllFilesInDir(tmpPath, include, exclude, false);
compressor.compressFiles(rootFiles, outputfile); // 1. compress list of files
vector<wstring> dirList = Utilities::getSubDirectoryList(tmpPath);
for (auto str : dirList) {
wstring dirName = str;
compressor.compressDirectory(dirName, outputfile, true); // 2. compress a secondary list of dirs
// more code follows here

The first compressor.compressFiles call succeeds. The compressor.compressDirectory however fails. Does this library support adding files to an existing archive?

If not, is there some other way of doing what I'm after using this library (i.e add a list of files, then add a secondary list of files to the same archive)?

Invalid exception code when testing an archive

When I using "bit7z::BitExtractor test()" to test an archive, on Windows XP SP3 and Windows Vista SP2, when happen an error, I receive always the error code E_FAIL by "bit7z::BitException getErrorCode()"
This do not happen on Windows 7 and later.
Tested with 32 bit executable.

To test this behavior, I used the "LockHunter" program (https://lockhunter.com/) which allows you to close the handles on the .7z file being tested.
I should receive the E_HANDLE error code.
The problem does not occur during compression on the temporary ".7z.tmp" file: I receive the correct error code E_HANDLE.
I have not tested the extraction.

E_HANDLE (Invalid Handle) is define as HRESULT_TYPEDEF(0x80070006L)

Bug]:

bit7z version

3.1.x

7-zip version

v18.05

7-zip DLL used

7z.dll

MSVC version

2017

Architecture

x86_64

Which version of Windows are you using?

Windows 10

Bug description

0x00007FFC797B4ED9 处(位于 7z.exe 中)有未经处理的异常: Microsoft C++ 异常: bit7z::BitException,位于内存位置 0x000000DE7A4FF498 处。 #

Steps to reproduce

0x00007FFC797B4ED9 处(位于 7z.exe 中)有未经处理的异常: Microsoft C++ 异常: bit7z::BitException,位于内存位置 0x000000DE7A4FF498 处。

Expected behavior

##0x00007FFC797B4ED9 处(位于 7z.exe 中)有未经处理的异常: Microsoft C++ 异常: bit7z::BitException,位于内存位置 0x000000DE7A4FF498 处。

Relevant compilation output

0x00007FFC797B4ED9 处(位于 7z.exe 中)有未经处理的异常: Microsoft C++ 异常: bit7z::BitException,位于内存位置 0x000000DE7A4FF498 处。

Code of Conduct

Support for In-Memory Operations

In particular:

  • Compression from filesystem to memory
  • Compression from memory to memory
  • Compression from memory to filesystem
  • Extraction from filesystem to memory
  • Extraction from memory to memory
  • Extraction from memory to filesystem

BitMemCompressor not working ?

Hello and thanks for this library !

Describe the bug

I try to use MemCompressor to write a buffer into an archive, a buffer that I got while extracting a paint-made BMP that I packed into a 7z archive.

When I try to compress the buffer into an archive, I have a Bit Error, invalid arg exception at Update Items with an empty error message

To Reproduce

Steps to reproduce the behavior:

  1. Tools initialisation :
    bit7z::Bit7zLibrary lib(L"7za.dll");
    bit7z::BitMemCompressor memcompressor(lib, bit7z::BitFormat::SevenZip);
    bit7z::BitExtractor extractor(lib, bit7z::BitFormat::SevenZip);

  2. Buffer extraction :

std::vector buffer;
extractor.extract(L"D:/Travail_Hassim/bit7z/x64/Debug/LZMA2.7z", buffer);

  1. Buffer compression ( Error happens here) :

memcompressor.compress(buffer, L"D:/Travail_Hassim/bit7z/x64/Debug/outputdir/testarchive.7z",L"TestArchive2");

Expected behavior

testarchive.7z to appear with the buffer data in it

Environment details (put an x in all the boxes that apply):

  • bit7z version:

    • v3.0
    • v3.1
  • 7-zip version:

    • v18.05
  • MSVC version:

    • 2017
  • Windows version:

    • Windows 10
    • SDK version : 10.0.17763.0
  • Architecture:

    • x86_64

setProgressCallback does not work when compressing the directory

I have been looking for a lot of solutions for archiving in Inno Setup, so luckily I found this project on github, it helped me solved my problem, but there is a small bug, I hope you can be fixed it. Thank you very much.

Describe the bug
I am writing the archive help functions with Win32 DLL, which will be used for InnoSetup in compressing and extracting files and folders. I'm having trouble exporting information about the process of compressing the folder out of the screen, which causes the program to freeze. Conversely, the information of the extraction process displayed on the screen works very well.

To Reproduce
Steps to reproduce the behavior:

typedef void(__stdcall *ExportProgressCallback)(int progress);
typedef void(__stdcall *ExportFileCallback)(const char* filename);

ExportProgressCallback progress_callback;
ExportFileCallback file_callback;
uint64_t global_total_size = 0;

void Bit7zTotalCallback(uint64_t total_size) {
	global_total_size = total_size;
}
void Bit7zProgressCallback(uint64_t progress_size) {
	progress_callback(int(progress_size * 100 / global_total_size));
}
void Bit7zFileCallback(wstring filename) {
	file_callback(ConvertFromWString(filename.c_str()));
}

EXPORT int __stdcall CompressDirectory(int format, LPCWSTR input, LPCWSTR ouput, LPCWSTR dll, ExportProgressCallback export_progress_callback, ExportFileCallback export_file_callback, char* exception, size_t exception_length) {
	try {
		Bit7zLibrary lib(wstring(dll).c_str());
		BitCompressor compressor(lib, GetBitInOutFormat(format)); //Format is zip in this case
		progress_callback = export_progress_callback;
		file_callback = export_file_callback;
		compressor.setTotalCallback(Bit7zTotalCallback);
		compressor.setProgressCallback(Bit7zProgressCallback); // Not working
		compressor.setFileCallback(Bit7zFileCallback);
		compressor.compressDirectory(input, ouput);
	}
	catch (const std::exception& ex) {
		strncpy(exception, ex.what(), exception_length);
		exception[exception_length - 1] = 0;
		return COMPRESS_FAILED;
	};
	return COMPRESS_SUCCESSFUL;
}

Expected behavior
When using "setProgressCallback", the program will freeze, the folder will not be compressed. If I don't use "setProgressCallback" but only use "setTotalCallback" and "setFileCallback", the program works well

Environment details (put an x in all the boxes that apply):

  • bit7z version:

    • v2.0
    • v2.1
    • v3.0
  • 7-zip version:

    • v16.02
    • v16.03
    • v16.04
    • v18.01
    • v18.03
    • v18.05
    • v19.00
  • MSVC version:

    • 2012
    • 2013
    • 2015
    • 2017
  • Windows version:

    • Windows Vista
    • Windows 8
    • Windows 8.1
    • Windows 10
  • Architecture:

    • x86
    • x86_64

CMake wrong target_include_headers scope

bit7z version

3.1.x

7-zip version

v19.00

7-zip DLL used

7za.dll

MSVC version

2019

Architecture

x86_64

Which version of Windows are you using?

Windows 10

Bug description

When built with cmake your lib just doesn't provide the user needed headers. For example, this code just won't compile because it cannot find bitextractor.hpp:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(uses_bit7z LANGUAGES CXX)

add_subdirectory(bit7z)
add_executable(uses_bit7z main.cpp)
target_link_libraries(uses_bit7z bit7z64)
// main.cpp
#include "bitextractor.hpp"

int main() {
    return 0;
}

Because of this code in your CMakeLists.txt:

target_include_directories(${TARGET_NAME} PRIVATE 
    ${PROJECT_SOURCE_DIR}/include/
    ${PROJECT_SOURCE_DIR}/lib/7zSDK/CPP/
)

Includes that end user will use must be marked as PUBLIC

Steps to reproduce

Just copy my example and try to build it. Even examples on README.md won't work

Expected behavior

My CMake example must work. Because it is default behaviour for CMake projects

Relevant compilation output

No response

Code of Conduct

Using the 7zip SDK to add files to an archive which already contains files

Hello Riccardo,

originally I wanted to use your library in our software. But my company insisted that I should take the 7zip SDK. Because I assume that you are experienced in the SDK, I address to you.

We have the following issue: We like to integrate the functionality of the 7zip SDK to add files to an archive. Files that are already in the archive should remain.

The SDK offers a nice C++ example: \CPP\7zip\UI\Client7z. It contains all things we aim for.

But there is an important problem. If the archive already exists and has some files in it, they disappear and only the new files are compressed in the archive.

I already have exchanged outFileStreamSpec->Create(archiveName, true) with outFileStreamSpec->Open(archiveName, OPEN_ALWAYS) in the Client7z example.

It would be nice, if you could explain how to solve this problem, best with code snippets.

Thanks in advance!

Custom read/write handlers from user

Describe the solution you'd like
Should allow user to set custom read/write handlers e.g when user wants to set http archive reading.

Additional context (optional)
This will make the library much more flexible and powerfull.
E.g user can set ftp/http archive url and the library should be able to list/extract without downloading the full archive via custom handlers.

Problems with extracting multi-volume

bug

Fails to extract files created by applying mult-volume.

Env

  • Windows 10
  • x86
  • msvc 2019
  • bit7z : v3.1.2
  • 7-zip : v16.04

Details

I set the volume size of 10mb

compressor.setVolumeSize(1024 * 1024 * 10);

Files smaller than the volume size were successfully extracted. ('myfile.001' file only ).
However, extract fails when multiple files are created. ('myfiles.001 ... myfiles.021')

Extraction by programming fails, but Extraction succeeds when an external 7z program is used. So I think compression is not a problem.

The code where the failure occurs is this:

IInArchive* BitInputArchive::openArchiveStream( const BitArchiveHandler& handler,
                                                const wstring& name,
                                                IInStream* in_stream ) {

    ... 

    // Trying to open the file with the detected format
    HRESULT res = in_archive->Open( in_stream, nullptr, open_callback );

    ...    

}

res is S_FALSE !!

Is it possible to remove items from archive?

Feature description

The title speaks for itself: is it possible to remove/delete items directly from existing archive?

By "directly" I mean without extracting the archive first to temporary folder on a disk, then removing the items from the disk and compressing it again.

After experimenting with 7z command line tool, it seems to me that 7zip is able to do this. There is a command option for this https://sevenzip.osdn.jp/chm/cmdline/commands/delete.htm and by observing the speed of this operation, it definitely is faster than extracting and compressing back.

Additional context

No response

Code of Conduct

Problems with paths longer than 259 characters

I have this path on my hard disk (without quotes):
"C:\Cartella Condivisa\DITTE STUDIO BELLON SRL\CONTABILITA' ORDINARIE\GENTOREMONA SRL IN LIQUIDAZIONE (CESSATA 01.04.2019)\BILANCIO FINALE DI LIQUIDAZIONE\BILANCIO FINALE DI LIQUIDAZIONE"

In the final folder I have the following files (without quotes):
"Delega Gentono Fabio in favore della moglie Torramini Silvana Claudia.as"
"Delega Gentono Fabio in favore della moglie Torramini Silvana Claudia.pdf"
"Delega Gentono Fabio in favore della moglie Torramini Silvana Claudia.pdf.p7m"

I use this code:
bit7z::Bit7zLibrary lib{ L"7z.dll" };

	bit7z::BitCompressor compressor{ lib, bit7z::BitFormat::SevenZip };

	compressor.setCompressionMethod(bit7z::BitCompressionMethod::Lzma2);
	compressor.setCompressionLevel(bit7z::BitCompressionLevel::FAST);

	compressor.compressDirectory(L"C:\\Cartella condivisa", L"D:\\Output.7z");

Only the first file "Delega Gentono Fabio in favore della moglie Torramini Silvana Claudia.as" is present in the "Output.7z" and no error occurs.

I use 7zip Dll v19.00, Bit7z v3.1.1 and Windows 10 x64 v1909
I have tested with "Windows 10 long path name" enabled and disabled: same result.

I have 7zip installed (v19.00) and if I compress "Cartella Condivisa", all the files are compressed (also if "Windows 10 long path name" is disabled).

[Question] Extract files/folders matching complex pattern?

Before describing my issue please allow me to thank you for this great, well written, and simple to use library which I just discovered, and which you are so generously providing free of charge -- I really appreciate it.

I would like to extract files from an archive using a complex pattern. From the documentation it seems that BitExtractor::extractMatching() method should be used, but its pattern support does not seem to be documented.

I checked the code in BitExtractor.cpp and to me it seems that it supports filesystem wildcards such as ? and *. Sadly, that is not adequate for my use case (I am unpacking NVIDIA drivers), because I want to use regex to match multiple variants of paths inside an archive.

I see that there is also a callback support (FileCallback) but to me it seems that it doesn't allow to cancel either the current file or the whole operation so that appears to be a dead-end too as far as I am concerned.

There are at least two approaches to solving this issue:

  1. Provide a BitExtractor::extractMatchingRegex() method which accepts regex string instead of filesystem wildcard pattern.
  2. Provide a callback which is receiving current item path (not just name), and which allows skipping an item and/or ending the archive operation based on its return value.

Personally, I would prefer the option 1 and I believe it would be simple and fast to implement.

An example of my regex filter for extraction of NVIDIA drivers:

std::wstring DriverExtractRegex = LR"(^(Display\.(Driver|Optimus)|HDAudio|MSVCRT|NGXCore|NVI2|PhysX|PPC).*$|^GFExperience\\(PrivacyPolicy\\PrivacyPolicy_[a-z]{2}\-[A-Z]{2,3}\.htm|EULA.html|FunctionalConsent_[a-z]{2}\-[A-Z]{2,3}\.txt)$|^(ListDevices|license|EULA)\.txt$|^setup\.(cfg|exe)$)";

An example of archive for extracting (542.8 MB download):
http://us.download.nvidia.com/Windows/431.60/431.60-desktop-win10-64bit-international-whql.exe

I am looking forward to your thoughts on this issue.

file callback is not the current compressing file

Hi,

Sorry to bother you again.

I know the callback mechanism could not guarantee the filename which file callback return to you is the real time file been compressed. But I make a scenario that a large file(take more than 20s to compress) and a small file. And the file callback give me the large file first and immediately give me the small file and then it takes 20s until the program end.

I think the file callback should guarantee that if the 7z is compressing a large file , the last filename retrieved from the file callback is the large file.

If I made any mistake and get the wrong conclusion, I apologize and hope you can point out.

Thank you!

[Bug]: inconsistency in the file Build.txt in v3.1.4

bit7z version

3.1.x

7-zip version

v19.00

7-zip DLL used

7z.dll

MSVC version

2017

Architecture

x86_64

Which version of Windows are you using?

Windows 10

Bug description

Is not a real bug.

In the 7z files released of v3.1.4 the "Build.txt" file reports the v3.1.3.
Is the released library the v3.1.4?

Thanks in advance, Fabrizio.

Steps to reproduce

No response

Expected behavior

No response

Relevant compilation output

No response

Code of Conduct

Crash at compressOut

Describe the bug
it crash just sometimes, but don't know why.

crash compressOut
source paths:
F:/01-绿色包备份/压缩包/DIYHomeV3.6.0测试/DIYHomeV3.17.0.03测试版本/Data/5/Scheme/jd004/4223E0B5-7B5E-423e-8C61-8148EAB96E43/X1000042001072/00/X1000042001072-16257152697900836.jx
F:/01-绿色包备份/压缩包/DIYHomeV3.6.0测试/DIYHomeV3.17.0.03测试版本/Data/5/Scheme/jd004/4223E0B5-7B5E-423e-8C61-8148EAB96E43/X1000042001072/00/X1000042001072-16257152697900836.jpg
F:/01-绿色包备份/压缩包/DIYHomeV3.6.0测试/DIYHomeV3.17.0.03测试版本/Data/5/Scheme/jd004/4223E0B5-7B5E-423e-8C61-8148EAB96E43/X1000042001072/00/X1000042001072-16257152697900836_H.json
F:/01-绿色包备份/压缩包/DIYHomeV3.6.0测试/DIYHomeV3.17.0.03测试版本/Data/5/Scheme/jd004/4223E0B5-7B5E-423e-8C61-8148EAB96E43/X1000042001072/00/X1000042001072-16257152697900836_AttachH.json
target path:
F:/01-绿色包备份/压缩包/DIYHomeV3.6.0测试/DIYHomeV3.17.0.03测试版本/data/5/order/12924/47bb14b0d0274976ad87b7c08fabf3b4/4223E0B5-7B5E-423e-8C61-8148EAB96E43/X1000042001072-16257152697900836.zip

Expected behavior
A clear and concise description of what you expected to happen.

Environment details (put an x in all the boxes that apply):

  • bit7z version:

    • v2.0
    • v2.1
    • [x ] v3.0
  • 7-zip version:

    • v16.02
    • v16.03
    • v16.04
    • v18.01
    • v18.03
    • v18.05
    • [x ] v21.02
  • MSVC version:

    • 2012
    • [x ] 2013
    • 2015
    • 2017
  • Windows version:

    • Windows Vista
    • Windows 8
    • Windows 8.1
    • [ x] Windows 10
  • Architecture:

    • [ x] x86
    • x86_64

Additional context
here is the call stack:
vrfcore.dll!_VerifierStopMessageEx�() Unknown
vrfcore.dll!VfCoreRedirectedStopMessage(unsigned long,char *,unsigned long,char *,unsigned long,char *,unsigned long,char *,unsigned long,char *) Unknown
vrfcore.dll!VfCoreRtlFreeHeap(void *,unsigned long,void *) Unknown
oleaut32.dll!APP_DATA::FreeCachedMem(void *,unsigned long) Unknown
oleaut32.dll!SysFreeStringImpl(unsigned short *) Unknown
oleaut32.dll!_VariantClearWorker@4�() Unknown
oleaut32.dll!_VariantClear@4�() Unknown
7z_21.dll!564e48db() Unknown
7z_21.dll![Frames below may be incorrect and/or missing, no symbols loaded for 7z_21.dll] Unknown

App.dll!compressOut(IOutArchive * out_arc, ISequentialOutStream * out_stream, bit7z::UpdateCallback * update_callback) Line 42 C++
App.dll!bit7z::BitArchiveCreator::compressToFile(const std::wstring & out_file, bit7z::UpdateCallback * update_callback) Line 267 C++
App.dll!bit7z::BitCompressor::compressOut(const std::vector<bit7z::filesystem::FSItem,std::allocatorbit7z::filesystem::FSItem> & in_items, const std::wstring & out_file) Line 119 C++
App.dll!bit7z::BitCompressor::compress(const std::vector<std::wstring,std::allocatorstd::wstring> & in_paths, const std::wstring & out_file) Line 42 C++
App.dll!bit7zCompressFiles(const std::vector<std::string,std::allocatorstd::string> & vecFiles, const std::string & strTargetPath) Line 170 C++

Auto detection of (input) archive file format

How to determine the archive file format (i.e. detect whether a .rar file is RAR or RAR5)?
Unfortunately using bit7z there is no direct method to detect the archive file format.
I think that there are two alternative ways that can be used to overcome this:

  1. You can read the file signature (e.g. as it can be seen here, RAR and RAR5 formats have slightly different file signatures)
    or
  2. If you're using the latest version of bit7z (v3.0.0), you can "indirectly" use the new BitArchiveInfo class.
    In fact, since its constructor throws an exception if the specified file format is not the one of the input file, you could, for example, write a function like the following one:
/* it detects the RAR archive format version of the input file
   (or it throws a BitException if it is not a RAR archive at all) */
const BitInFormat& detectRAR( const wstring& in_file ) {
    Bit7zLibrary lib( L"7z.dll" );
    try {
        BitArchiveInfo info( lib, in_file, BitFormat::Rar );
        //if BitArchiveInfo constructor did not throw an exception, the archive is RAR (< 5.0)!
        return BitFormat::Rar;
    } catch ( const BitException& ) {
        /* the archive is not a RAR and if it is not even a RAR5, 
           the following line will throw an exception (not catched)! */
        BitArchiveInfo info( lib, in_file, BitFormat::Rar5 );
        return BitFormat::Rar5;
    }
}

I think that a more generic (i.e. not only RAR) archive format detection is possible using the same concept, even though it could be kind of tricky, since we cannot iterate over the many format constant objects (BitFormat::...).
Anyway, I hope to implement a more easy to use format detection in the next stable version (v3.1), maybe using the first method or exploiting some (still unknown, at least to me) functionality of 7-zip.

can you post a sample solution in the wiki?

Hi

I checked the bit7z everyday to see whether you add the callback function. Thank you very much, I am really appreciate your effort.

I try to make a sample solution to test the function and I can compile and link, But when I debug the code ,the line "Bit7zLibrary lib(L"7z.dll");" will abort. I put the 7z.dll in the folder where the exe exist and the dependency walker said nothing dll was missing.

So, can you post a sample solution to teach me how to use the lib? Thank you~

Isolate the platform-independent functionality

I'd like to build this on Linux so my project can zip files without depending on libz. Would it be possible to separate the Windows-dependent parts from a platform-independent core, so that I can integrate the compression functionality into my project? If you can give me some ideas how to do this, I could give it a try.

It would also be nice to perform in-memory operations on the basis of stdlib classes such as istream and ostream. I wouldn't normally have data in a vector<byte_t> format. It can be converted without a copy, but it requires an awkward usage of vector. This is one the main reasons we have the stream classes.

Is it possible to use the library with static linking?

I'm looking for a static library which allows to unzip files with password. From the description of bit7z I see it supports static linking and extracting files with password but from docs I noticed that I have to put 7za.dll into the running directory. Does this library support fully static linking? I'd like to compile single exe without additional dll dependencies.

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.