Giter Site home page Giter Site logo

sevenzipextractor's Introduction

Hi! Nice to meet you.

Thank you for dropping by.

  • Founder of Limetime.io - RFID Sports timing system hardware and software
  • Founder of Documentoved.ru - Russian legal-tech document saas (LLC, contracts)
  • Founder of Pangali.ru - Sports leisure booking app
  • Founder of thebestshelf.ru - ML powered shelf product placement tool for retail
  • Founder of suggestapp - ML powered API that understands your taste (wine, beer) and suggest products you will like for sure.
  • Former WildApricot / Personify developer

Results of my work are used by millions around the globe

I wonder how it is to have 1k stars β­πŸ˜„ 68 remaining! πŸš€ 😎

My GitHub stats

profile for Alexander Selishchev on Stack Exchange, a network of free, community-driven Q&A sites

sevenzipextractor's People

Contributors

adoconnection avatar ied206 avatar josepineiro avatar leoying31 avatar matortheeternal avatar mmoosstt avatar rabanti-github avatar sudoudaisuke avatar wojciechnagorski 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

sevenzipextractor's Issues

Unable to open CAB archive

Hi,

I would like to open a cab file, as it written to be supported.
I get this error: "Unable to open archive".

do you knwon why?

Thanks!

Extracting a file from a .deb file

I'm trying to extract a single file from a debian package. I extract the top level and it has two tar.xz files (control.tar.xz and data.tar.xz). The file I want is in data.tar.xz. I can create a new ArchiveFile instance of it, but it has only one entry (I'm assuming its data.tar), but the entry has no filename. This seems to prevent me from extracting it.

How do you either: 1) recursively extract everything in the .deb file, or 2) extract a nameless .tar file from within a tar.xz file?

NET6 support

Can you please add NET6 support? I tried to compile your source, works great (but I prefer the nuget packages to be uptodate). Only added net6.0-windows in target frameworks, hope this is the golden line.

Only one change necessary to prevent warnings during compilation time in file SafeLibraryHandle.cs, but it's only cosmetical thing I suppose (see also here).

Remove this line:

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]

I am unable to extract an .exe (7z self extracting archive) using SevenZipExtractor

 var file = @"C:\Users\PC\Desktop\SelfExtractFile.exe";
 var destination = @"C:\Users\PC\Desktop\";

 using ( ArchiveFile archiveFile = new ArchiveFile(file))
 {
   archiveFile.Extract(destination, true);
 }

I get: : 'Object reference not set to an instance of an object.' archive and entries are null.

The library says it supports .exe.

Any idea how to fix this?
This is the command for creating the file:
7z a -sfx7z.sfx "SelfExtractFile.exe" "C:\Users\PC\Desktop\*.*" -mmt -r

Exception "Unable to open archive" received when opening valid 7z archives

Hello,

I recently found this project and tried to implement it in a download/extractor tool for 7z files.
The implementation worked flawless as there is almost nothing that could go wrong.

Then I ran into a problem that some 7z files I tried to unpack failed with "Unable to open archive". Other archives show no problem. I checked these bad archives with the original 7z Manager and no error was found.
What I tried so far:

  • Analyzed the bad archives with older and latest version of 7z Manager --> No issue found
  • Exchange the 7z.dll with the latest or way older versions --> No effect
  • Analyzed the header and end header of the bad archives in a hex editor, according to the info from this page: https://www.7-zip.org/recover.html--> Archive seems to be valid as the length matches.

These are the infos about one of the bad archives:
Size: 16 988 619 434
Packed Size: 10 451 321 462
Folders: 41
Files: 834
CRC: 18147D68
Type: 7z
Physical Size: 10 451 328 505
Headers Size: 7 043
Method: LZMA2:24
Solid: +
Blocks: 9

Header
000000000 37 7A BC AF 27 1C 00 04 44 B9 FA 12 B2 9D F2 6E
000000010 02 00 00 00 27 00 00 00 00 00 00 00 85 30 51 92

End Header
26EF29DD0 00 00 17 06 F2 76 82 F2 6E 01 09 9B 3C 00 07 0B
26EF29DE0 01 00 01 23 03 01 01 05 5D 00 80 01 00 0C C1 4E
26EF29DF0 58 0A 01 52 87 74 D0 00 00

My last action was to pull the code and used the "Example"-Project to open the bad archive and see where it exactly fails.
All I see is, that this function call in "ArchiveFile.cs:155" returns 0x00000001
int open = this.archive.Open(this.archiveStream, ref checkPos, null);
this.archiveStream.Position is 0x0000000000000020

I'm not generating the archives on my own, therefore I can't tell what could causes the archives to get in this state.
Any help appreciated.

7z - unknown archive exception

Hi,
Thank you for the nuget package and wrapper :)
I have come across a little issue trying to open a 7z archive, it throws the exception
7z is not a known archive type

If i rename the archive to .SevenZip it then works. So guess it's just a problem with detecting the type from the file extension ?

thanks
Mike

How to chanage unzipped file folder?

Hello:
I usually download a number of zipped files with multiple files inside, and default download drive is not big enough to hold many big files.
Therefore, I want to use the repo to unzip all the downloaded zip files to another drive.
But I can't figure out how to change the path for unzipped files.
Please advise.
I am using SevenZipExtractor 1.0.17 on Windows 10 (Version 21H2).
Thanks,

Very slowly on large 7z archives

I have an archive larger than 1Gb. The archive contains about 3500 files. The largest file in the archive is about 6 Gb.

I use:

using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.7z"))
{
    foreach (Entry entry in archiveFile.Entries)
    {
        // extract to file
        entry.Extract(newFileName);
    }
}

In comparison with a regular 7z extractor, it works hundreds of slower

Extracted files are locked

Extracted files are locked in my scenario:
when extracting files one by one in foreach and trying to open them, access is denied.

The problem is in Entry.cs ( https://github.com/adoconnection/SevenZipExtractor/blob/master/SevenZipExtractor/Entry.cs )

public void Extract(string fileName)
        {
            this.Extract(File.Create(fileName));
        }

which has to be changed to something like below (or other disposal variant) to prevent the locking

public void Extract(string fileName)
        {
            using (FileStream fs = File.Create(fileName))
                Extract(fs);
        }

By the way, thanks for the great wrapper. Really enjoy using it! Бпасибо! :)

Unable to cast COM object of type 'System.__ComObject' to interface type 'SevenZipExtractor.IInArchive'.

I have a project in .NET Core 3.1 and it will not extract an entry.
This is the code that is causing the issue, and it is happening in archive.Entries[i].Extract(archive.Entries[i].FileName);.

for (int i = 0; i < archive.Entries.Count; i++)
{
    if (archive.Entries[i].FileName.EndsWith('/'))
        Directory.CreateDirectory(archive.Entries[i].FileName);
    else
        archive.Entries[i].Extract(archive.Entries[i].FileName);
}

The exact error I get is this:

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'SevenZipExtractor.IInArchive'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{23170F69-40C1-278A-0000-000600600000}' failed due to the following error: No such interface supported (0x80004002 (E_NOINTERFACE)).
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at SevenZipExtractor.IInArchive.Extract(UInt32[] indices, UInt32 numItems, Int32 testMode, IArchiveExtractCallback extractCallback)
   at SevenZipExtractor.Entry.Extract(Stream stream)
   at SevenZipExtractor.Entry.Extract(String fileName, Boolean preserveTimestamp)
   at ConsoleApplication17.ArchiveFile.Extract() in C:\Users\Jose\Documents\GitHub\ConsoleApplication17\ConsoleApplication17\ArchiveFile.cs:line 60
   at ConsoleApplication17.ExtractWindow.<>c__DisplayClass4_0.<ExtractWindow_Shown>b__0() in C:\Users\Jose\Documents\GitHub\ConsoleApplication17\ConsoleApplication17\ExtractWindow.cs:line 73

All I have done was install the Nuget package, and replace a old method I had used that involved System.IO.Compression to this.

extraction multi file zip archive -> failes

As it seems SevenZipExtractor cannot handle multi file archives, can it?

File.7z.001
File.7z.002
File.7z.003
using(ArchiveFile archiveFile = new ArchiveFile("File.7z.001")) {
   archiveFile.Extract(extractPath); // extract all
}

-> exception

Solid Extract to MemoryStream or List

I see a function named ExtractToList, but I am unsure on how to use it or if it does what I think it does. In the wiki it states that it's better to extract the whole archive at once if it's a solid archive. The example is for file extraction. I'd like to do this into memory.

As the wiki explained, even putting the 7zip file into memory first doesn't help with the speed.

So if it's possible to quickly extract all the files from a solid archive at once into memory, then how, and if not, is it possible to add it?

(I'm actually not sure how Func works, so pardon my ignorance)

cannot extract deb file

Hi,

I use this code, but I get an exception (tried several different deb files):

Using archiveFil As ArchiveFile = New ArchiveFile("D:\temp\autogen-5.18.12_armhf.deb") 
            For Each Entry In archiveFil.Entries
                If Not Entry.IsFolder Then
                    Console.WriteLine(Entry.FileName.ToString)
                    'Dim ms As MemoryStream = New MemoryStream
                    'Entry.Extract(ms)
                End If
            Next
End Using

Object reference not set to an instance of an object.

What's wrong?

SevenZipExtractor.SevenZipException: '7z.dll not found'

SevenZipExtractor.SevenZipException
HResult=0x80131500
Message=7z.dll not found
Source=SevenZipExtractor
StackTrace:
at SevenZipExtractor.ArchiveFile.InitializeAndValidateLibrary()
at SevenZipExtractor.ArchiveFile..ctor(Stream archiveStream, Nullable`1 format, String libraryFilePath)
at ConsoleApplication87.Program.Main(String[] args) in C:\temp\Zip\SevenZipExtractor-master\SevenZipExtractor-master\Benchmark\Program.cs:line 75

Do you know what is missing? where?

Dll downloaded from nuget doesn't extract LZH file

When using dll from nuget package in version 1.0.12 extraction from lzh file doesn't work (0 entries and Exception).
When I get a dll from repository (exemple project) everything works perfect.
Please update nuget version of library.

arj when changing a computer

I transferred the program to another computer, SevenZipExtractor stopped opening arj archives (does not see files in them)

SevenZipExtractor.ArchiveFile szip = new SevenZipExtractor.ArchiveFile(localDirectory + fileName);
 foreach  (Entry e in szip.Entries)   {....}

```no entry in szip.Entries
but on an old computer everything works

Minimal example doesn't work...

The sample code below does nothing but throw this exception:
System.InvalidCastException: 'Unable to cast object of type 'System.UInt32' to type 'System.UInt64'.'
.. where it attempts to display the number of files in the archive. I installed version 1.0.12 via the NuGet PM in Visual Studio 2017.

using System;
using SevenZipExtractor;

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            using (ArchiveFile archiveFile = new ArchiveFile(@"G:\batch\ANSIMATE.ARJ")) {
                Console.WriteLine("There's {0} files in the archive.", archiveFile.Entries.Count);
            }
        }
    }
}

Suggestions?
tnx.

g.

Reliance on "C:\Program Files\7-Zip"

Hi there

We have just started using this, and it appears to be the case that it relies upon 7-Zip being available at "C:\Program Files\7-Zip".

Our deployed app wasn't working, and this was the way we found to fix it. Copying the files in to the same directory as our executable didn't work, and neither did installing 7-zip in to a different location.

Cheers

Cedd

Extract to stream when entry is in folder

I try to extract an entry to a memorystream, but this fails if the entry is in a directory in the archive.

My code is this:

using (ArchiveFile archiveFile = new ArchiveFile(FilePath)) {
                PageCount = archiveFile.Entries.Count;

                MemoryStream memoryStream = new MemoryStream();
                archiveFile.Entries.OrderBy(x => x.FileName).First().Extract(memoryStream);

               Image = Image.FromStream(memoryStream);
            }

This code works fine when the entry is in the root of the archive. Is there a way to make this work without resorting to extracting to file?

Bzip2 archives cannot be extracted

It looks like bizp2 archives (.bz2) cannot be extracted at all.
I tested the extraction, using the example program:

using (ArchiveFile archiveFile = new ArchiveFile(@"C:\temp\test.txt.bz2"))
            {
                // extract all
                archiveFile.Extract("Output");
            }

The format is guesses as expected as Formats.BZip2 and the number of containing entries are also correct.
However, in the method entry.Extract(entry.FileName);, the enclosed files cannot be extracted.
The problem occurs in the line 104 of ArchiveFile.cs.
The entries do not contain any valid values:

  • dates are displayed as '01.01.0001 00:00:00'
  • CRC is 0
  • FileName is null
  • PackedSize is 0
    ... and so on.

The files can be extracted in 7Zip, though.
See attached example files as reference
exampleArchives.zip

Thank you in advance.

Versions 1.0.10 to 1.0.14 doesn't work

I install latest version SevenZipExtractor using nuget and I was trying the example code, but i have error

"The type or namespace name 'SevenZipExtractor' could not be found (are you missing a using directive or an assembly reference?)
I checked few more versions and problem diapers when i change version to 1.0.09

I'm using .net core 3.1

Application crash while getting Entries | System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Hi!
I have a project on .net 5 and I get an error when I try to unzip all occurrences, after which the application gets an unhandled exception and crashes.

My code:

using (ArchiveFile archiveFile = new ArchiveFile("D:\\01.zip"))
{
      var x = archiveFile.Entries;
      archiveFile.Extract("D:\\tmp\\", true);
}

Archive for testing: https://yadi.sk/d/dd3ZYRe5D89xzw

Error:
System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Thanks for any help on this issue.

Decompression is too slow

Decompression is too slow

using (ArchiveFile archiveFile = new ArchiveFile(@"Archive.7z"))
{
    foreach (Entry entry in archiveFile.Entries)
    {
        // extract to file
        entry.Extract(newFileName);
    }
}

License?

Could you clarify what license this project uses?

(I can't find it anywhere - the code project article this project emerged from is MIT licensed, but I can't take that for granted for this project.)

Rebase of later version

Hi,
In the main page, you mention that this is based of the CodeProject page (latest version of it on there is 1.5).
On website of the guy who originally made it, he did a "new" version in December 2008, with the following comments . . .
2.0 - Packing support introduced, added support for the latest 7-zip version (4.60+), demo updated to show basic packing principles
Update (2.0): Now demo can create simple archives. Also in this demo some issues found by CodeProject community users was fixed.

Maybe worth updating the base yours works from ?
http://dev.nomad-net.info/articles/sevenzipinterface :)

Zip files over 4 gig.

Working with zip files containing image files. When the files are larger than 4 gigs, the files up to 4 gig extract just fine, but all other files after that are 0 or 1 byte. I can extract them just fine with 7-zip. Looking at the archive, every file up to the 4 gig mark show characteristics NTFS, all files after that show characteristics Zip64 NTFS. I've tried extract all files, extract files one at a time, extract one at a time to stream. Thanks for any help on this issue.

MemoryStream's position is at the end

Not really a bug per say, but if you do:

MemoryStream memoryStream = new MemoryStream();
Entry entry.Extract(memoryStream);

Then you cannot do memoryStream.Read; simply because the position of the stream is at the end. So now you have to do:

MemoryStream memoryStream = new MemoryStream();
Entry entry.Extract(memoryStream);
memoryStream.Position = 0;

Before you can use the stream. I got bitten by this. It's not a bug but it's very counter intuitive and goes against typical designs we see elsewhere.

Exception : The string was not recognized as a valid DateTime

The string was not recognized as a valid DateTime

  • Unzip the package, abnormal! On some computers.
  • amd64.7z my files are normal
  • OS -- Windows 10 Enterprise LTSC
 try
  {

      using (SevenZipExtractor.ArchiveFile archiveFile = new SevenZipExtractor.ArchiveFile(sourceFileName))
      {
          archiveFile.Extract(destinationDirectory, true); // extract all
      }

  }
  catch (Exception ex)
  { 
      System.Windows.Forms.MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
      System.Environment.Exit(0);

  }
  finally { }

nuget package is constrained to net45

Package SevenZipExtractor 1.0.5 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package SevenZipExtractor 1.0.5 supports: net45 (.NETFramework,Version=v4.5)
One or more packages are incompatible with .NETCoreApp,Version=v1.0.
Package restore failed. Rolling back package changes for 'needyproject'.
Time Elapsed: 00:00:02.8476243
========== Finished ==========

Unable to initialize SevenZipHandle / Access Denied .NET 4.8???

I did have this working once, I passed in the dll path into the new ArchiveFile.
Locally and on Azure this no longer works.

If I take out the path, so my code just looks like this:
archiveFile = new ArchiveFile(zipDocumentStream, sevenZipFormat);

I get a "Unable to initialize SevenZipHandle
Win32Exception: Access is denied.

I have tried the last three versions of the SevenZipExtractor and all three give the same result. Any ideas?

Progress event

I already tried, and I can unzip LZMA2 files without problem. But how can I have a Progress?

is not support password?

i run benchmark, the archivefilename assigned to encrypted 7z file required to password
and then output error, unable to read archive.

SevenZipCompactor ?

Hello Adoconnection,

Thanks for this project, it's the only c# 7z.dll wrapper that is working fast, without cpu high usage or memory leak !
Have you any plan to add one simple "Add files to archive" interface ?
You can do it with the current 7z.dll :)
It would be great ! πŸ‘

Cheers

Error "Dynamic operations can only be performed in homogenous AppDomain"

With version 1.0.13 (not with 1.0.12), I got this error when used in conjuction with this app.config setting:

<NetFx40_LegacySecurityPolicy` enabled="true" />

The full error I get is:

System.InvalidOperationException: Dynamic operations can only be performed in homogenous AppDomain.

If I remove the app.config setting, everything works great. Is there a chance to make these working?

Thanks!

Can't instantiate SevenZipExtractor object using file name with no extension

Trying to call this...
Public Sub New(archiveFullName As String)
with this...
Dim SevenZipEx As SevenZip.SevenZipExtractor = Nothing
SevenZipEx = New SevenZip.SevenZipExtractor("C:\Temp\test")
Results in this exception...
startIndex cannot be larger than length of string." & vbCrLf & "Parameter name: startInde"

Is there a thread-safe way to extract files?

Hi there!
I'm working on a library where I sometimes I will need to extract files in a new thread so it won't stall other things, but the following doesn't work:

    Task.Factory.StartNew(() =>
    {
        archiveFiles.ToList().ForEach(entry =>
        {
            var validPath = Path.Combine(destinationPath, targetFolder);
            Directory.CreateDirectory(validPath);

            using (MemoryStream ms = new MemoryStream())
            {
                entry.Extract(ms); //throws exception
                FileStream fs = new FileStream(Path.Combine(validPath, entry.FileName), FileMode.Create);
                ms.WriteTo(fs);
                fs.Close();
            }
        });
    });

The full exception is:

System.Runtime.InteropServices.InvalidComObjectException: 'COM object that has been separated from its underlying RCW cannot be used.

I've searched that error around and it is said to be typical for operations that are not thread-safe. Is there a workaround or any plans to allow to perform this safely in the future?

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.