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 specific file to buffer #32

Closed
kenkit opened this issue Oct 3, 2019 · 7 comments
Closed

Extract specific file to buffer #32

kenkit opened this issue Oct 3, 2019 · 7 comments
Assignees

Comments

@kenkit
Copy link
Contributor

kenkit commented Oct 3, 2019

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 );
@kenkit
Copy link
Contributor Author

kenkit commented Oct 3, 2019

I can see the feature is there, the problem is it does not detect the archive type.

 Folders count: 0
 Files count: 3
 Size: 13551341
 Packed size: 13376716

Archive items
 Item index: 0
  Name: J110F_twrp.img.tar
  Extension: tar
  Path: J110F_twrp.img.tar
  IsDir: 0
  Size: 9533440
  Packed size: 9359154

 Item index: 1
  Name: UPDATE-SuperSU-v2.46.zip
  Extension: zip
  Path: UPDATE-SuperSU-v2.46.zip
  IsDir: 0
  Size: 4017098
  Packed size: 4017098

 Item index: 2
  Name: Password.txt
  Extension: txt
  Path: Password.txt
  IsDir: 0
  Size: 803
  Packed size: 464
Cannot detect the format of the file <---After listing the archive I extract to buffer

@kenkit
Copy link
Contributor Author

kenkit commented Oct 3, 2019

It is not working, it expects I input the path to the archive, not the path to the file.
So I think this is a valid feature request.

@rikyoz
Copy link
Owner

rikyoz commented Oct 3, 2019

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 );

Unfortunately, at the moment extracting a single file to a buffer by matching its name/path is not available: extraction by matching is supported only when the output target is the filesystem.

Implementing such functionality should not take much time, however it would potentially introduce redundancies in the code and avoiding them would take some time for reasoning; moreover, it would introduce also inconsistencies in the API which must be addressed!

It is not working, it expects I input the path to the archive, not the path to the file.
So I think this is a valid feature request.

Anyway, with the current version of bit7z there is a workaround: you can use the BitExtractor::extract(...) method, to which you can pass, as third parameter, the index (in the archive) of the file you need (you can get it using BitArchiveInfo if you don't already know it a priori).
For example:

const auto archive_name = L"archive.7z";
const auto file_path = L"path/to/another/file.txt"; // The path of the file you want to extract inside the archive
vector< byte_t > buffer;
BitArchiveInfo arc{ lib, archive_name, BitFormat::SevenZip };
auto arc_items = arc.items();
for ( auto& item : arc_items ) {
    if ( item.path() == file_path ) {
        // We have found the file we want to extract!
        BitExtractor extractor{ lib, BitFormat::SevenZip };
        extractor.extract( archive_name, buffer, item.index() );
        break;
    }
}

@rikyoz rikyoz self-assigned this Oct 3, 2019
@kenkit
Copy link
Contributor Author

kenkit commented Oct 3, 2019

Thanks for taking time to respond and also for the info. I will try this method instead.

@rikyoz
Copy link
Owner

rikyoz commented Oct 4, 2019

You're welcome!

@uq1
Copy link

uq1 commented Nov 19, 2019

Could we possibly get the ability to use pre-allocated C style buffers (eg: void *buf)?

Trying to use the library to load game files, but allocation of a new buffer and then copying is forcing me to double the ram usage of large files (700mb) on a 32 bit process, and running out of memory.

@rikyoz
Copy link
Owner

rikyoz commented Dec 6, 2019

Could we possibly get the ability to use pre-allocated C style buffers (eg: void *buf)?

Trying to use the library to load game files, but allocation of a new buffer and then copying is forcing me to double the ram usage of large files (700mb) on a 32 bit process, and running out of memory.

Supporting C style buffers would require really many changes in the internal code of bit7z, which extensively uses std::vector.
Anyway, for the next version I will evaluate how to support it, but it won't be anytime soon (due to other commitments).

rikyoz added a commit that referenced this issue Aug 13, 2021
rikyoz added a commit that referenced this issue Sep 2, 2021
rikyoz added a commit that referenced this issue Sep 4, 2021
@kenkit kenkit closed this as completed Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants