Coder Social home page Coder Social logo

squid-box / sevenzipsharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomap/sevenzipsharp

262.0 11.0 96.0 8.17 MB

Fork of SevenZipSharp on CodePlex

License: GNU Lesser General Public License v3.0

C# 99.65% XSLT 0.35%
7zip 7z compression extraction

sevenzipsharp's Introduction

This is a fork from tomap's fork of the original CodePlex project.




Project Archived

As of 2024-04-10, I've decided to officially release the final version of this fork - 1.6.2 - and archive the project. I myself don't use it anymore, and the sporadic bursts of activity from me aren't useful and I have a hard time even doing good code reviews on submitted code as I'm not actively working on this anymore.

The bugs that exist will remain, feel free to fork this repository (as I once did from tomap) if you want to fix something.




Continuous Integration

Squid-Box.SevenZipSharp Squid-Box.SevenZipSharp.Lite
NuGet Badge NuGet Badge

Changes from original project

As required by the GNU GPL 3.0 license, here's a rough list of what has changed since the original CodePlex project, including changes made in tomap's fork.

  • Target .NET version changed from .NET Framework 2.0 to .NET Standard 2.0, .NET Framework 4.7.2 and .NET Core 3.1.
  • Produces two NuGet packages, one full-feature package and a Lite variant without SFX support (and significantly smaller size).
  • Continous Integration added, both building and deploying.
  • Tests re-written to NUnit 3 test cases.
  • General code cleanup.

As well as a number of improvements and bug fixes.


Original project information below, some information might be outdated or won't apply to this fork:


Project Description

Managed 7-zip library written in C# that provides data (self-)extraction and compression (all 7-zip formats are supported). It wraps 7z.dll or any compatible one and makes use of LZMA SDK.

General

SevenZipSharp is an open source wrapper for 7-zip released under LGPL v3.0. It exploits the native 7zip dynamic link library through its COM interface and exports classes to work with various file archives. The project appeared as an improvement of http://www.codeproject.com/KB/DLL/cs_interface_7zip.aspx. It supports .NET and Windows Mobile .NET Compact.

The solution consists of SevenZipSharp library itself, console, WinForms and WPF test applications and the documentation. All are built with Microsoft Visual Studio 2008 or 2010 and under .NET 2.0 (up to 4.0). Sandcastle is used to build the library documentation. SevenZipSharp uses JetBrains ReSharper to maintain the quality of the code and NDepend to collect code statistics and audit the whole project. Special thanks to SciTech Software for .NET Memory Profiler.

Check SVN for the latest version of SevenZipSharp.

Quick start

SevenZipSharp exports three main classes - SevenZipExtractor, SevenZipCompressor and SevenZipSfx. SevenZipExtractor is a 7-zip unpacking front-end, it allows either to extract archives or LZMA-compressed byte arrays. SevenZipCompressor is a 7-zip pack ingfront-end, it allows either to compress archives or byte arrays. SevenZipSfx is a special class to create self-extracting archives. It uses the embedded sfx module by Oleg Scherbakov . LzmaEncodeStream/LzmaDecodeStream are special fully managed classes derived from Stream to store data compressed with LZMA and extract it. See SevenZipTest/Program.cs for simple code examples; SevenZipTestForms is the GUI demo application. You may find useful the SevenZipSharp documentation provided in CHM format. On Windows XP SP2 or later or Vista unblock the file to view it correctly.

Native libraries

SevenZipSharp requires a 7-zip native library to function. You can specify the path to a 7-zip dll (7z.dll, 7za.dll, etc.) in LibraryManager.cs at compile time, your app.config or via SetLibraryPath() method at runtime. + "7z.dll" is the default path. For 64-bit systems, you must use the 64-bit versions of those libraries. 7-zip ships with 7z.dll, which is used for all archive operations (usually it is "Program Files\7-Zip\7z.dll"). 7za.dll is a light version of 7z.dll, it supports only 7zip archives. You may even build your own library with formats you want from 7-zip sources. SevenZipSharp will work with them all.

Main features

  • Encryption and passwords are supported.
  • Since the 0.26 release, archive properties are supported.
  • Since the 0.28 release, multi-threading is supported.
  • Since the 0.29 release, streaming is supported.
  • Since the 0.41 release, you can specify the compression level and method.
  • Since the 0.50 release, archive volumes are supported.
  • Since the 0.51 release, archive updates are supported (0.52 - ModifyArchive). You must use the most recent 7z.dll (v>=9.04) for this feature.
  • Since the 0.61 release, Windows Mobile ARM platforms are supported.
  • Since the 0.62 release, extraction from SFX archives, as well as some other formats with embedded archives is supported.

Extraction is supported from any archive format in InArchiveFormat - such as 7-zip itself, zip, rar or cab and the format is automatically guessed by the archive signature (since the 0.43 release). You can compress streams, files or whole directories in OutArchiveFormat - 7-zip, Xz, Zip, GZip, BZip2 and Tar. Please note that GZip and BZip2 compresses only one file at a time.

SevenZipSharpMobile (SevenZipSharp for Windows Mobile) does not differ much from its big brother. See the difference table below.

Self-extracting archives

SevenZipSfx appeared in the 0.42 release. It supports custom sfx modules. The most powerful one is embedded in the assembly, the other lie in SevenZip/sfx directory. Apart from usual sfx, you can make even small installations with the help of SfxSettings scenarios. Refer to the "configuration file parameters" for the complete command list.

Advanced work with SevenZipCompressor

SevenZipCompressor.CustomParameters is a special property to set compression switches, compatible with command line switches of 7z.exe. The complete list of those switches is in 7-zip.chm of 7-Zip installation. For example, to turn on multi-threaded compression, code .CustomParameters.Add("mt", "on"); For the complete switches list, refer to SevenZipDoc.chm in the 7-zip installation.

Conditional compilation symbols

These compilation symbols are supported: UNMANAGED.

  • UNMANAGED allows the main COM part of SevenZipSharp to be built.

sevenzipsharp's People

Contributors

amarendrabiorad avatar benjicoh avatar bneidhold avatar chester89 avatar dialpawlowski avatar doug24 avatar elihwyma avatar fgimian avatar huhen avatar in1gma avatar kikijiki avatar mgamerz avatar panda73111 avatar pysj avatar ravibpatel avatar squid-box avatar thoemmi avatar tomap avatar toofderling avatar yashbajra 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

sevenzipsharp's Issues

Checking licensing

license file states GPL 2.1, but many other parts of the project mentions 3.

Figure out which one to use and ensure it's the same throughout the project.

Follow-up on #6

#10 fixed #6, but I don't understand why this is ocurring in the first place, and only for .bz2 and .gz files.

Translate original tests into NUnit tests

The original project has some programs for testing SevenZipSharp, but these don't work very well since they're dependent on test files that are not in the project itself.

Tests that are estimated to be translated into NUnit tests:

  • Extraction
  • Extraction (multi-threaded)
  • Extraction (streaming)
  • Compression
  • Compression (multi-threaded)
  • Compression (streaming)
  • Compress (custom parameters)
  • "Toughness test"
  • "Serialization demo"
  • Self extracting archives (SFX)
  • Lzma Encode/Decode Stream test (?)

Uzipping 7z files from resources

I am trying to store the 7z.dll(s) in my resources. I used to use the ionic.dll library and was able to unzip files from resources in memory, but I am having a hard time figuring out how to do the same with a 7z files. I tried

Dim currentAssembly = Reflection.Assembly.GetEntryAssembly()
Dim currentDirectory = New FileInfo(currentAssembly.Location).DirectoryName.ToString
Dim path As String = currentDirectory + "My.Resources\" And If(IntPtr.Size = 4, "7z86.dll", "7z64.dll")

 Using extractor = New SevenZipExtractor("My.Resources.Source.7z", "Pass1")
            For i = 0 To extractor.ArchiveFileData.Count - 1
               If extractor.ArchiveFileData(i).tostring.contains(Desired_File_Name) then
                  extractor.ExtractFiles(OutputDirectory, extractor.ArchiveFileData(i).Index)
'unzip file in memory and load to richtextbox               
'Richtext1.LoadFile(msss, RichTextBoxStreamType.RichText)
                  Exit For
               End If
            Next
        End Using

I know the code above doesn't work, I have been trying to go through the tests to make work with no success. I am trying to access the encrypted file, locate the file based on its name, unzip the file in memory and load it to a richtextbox. Do you think that is possible with this library?

Thanks in advance,
Beho

extraction of password protected archive without encrypted filenames

Nuget package: Squid-Box.SevenZipSharp 1.1.106

I've got password protected ZIP archive without encrypted filenames inside. When I try to unpack such archive without any password, it extracts zero sized files to the output folder. No exception is raised.

var extractor = new SevenZipExtractor(path_to_archive)
extractor.Check() returns true which is not correct
var extractor2 = new SevenZipExtractor(path_to_archive, "correctpassword");
extractor2.Check() also returns true which is correct this time

Is there any way how to prevent such behavior or some kind of workaround? The only workaround I come up with is to try to extract the first file in archive and check its size...

Thank you
David

Rename target folder

Hello, can I extract files changing filenames?

For example archive struct is:
root/folder1/file.txt

I want at the end:
my folder/file.txt

SevenZipExtractor.ExtractArchive() hangs when the path is too long

Dear Community,

I just recognized that the version 1.0.19.0 simply hangs at SevenZipExtractor.ExtractArchive(), when the path is too long, there is no exception, the function just never returns.
In a former version there was a PathToLongException.
Has anyone an idea how to prevent hanging?

Thanks and best regards,
Jürgen

ModifyArchive does not work on password protected archives

I want to rename and/or delete files from a 7z archive

When I use this code (i.e. no password) it works. It creates the zip. I can open it in 7zip and extract files, etc in the archive created in the first step. Also the first file is renamed and the second removed.

Dim Compressor As New SevenZip.SevenZipCompressor
Compressor.EncryptHeaders = True

Compressor.CompressFiles("d:\temp\test.7z", {"D:\Temp\svg.txt", "D:\Temp\tmp.txt"})

Dim NewList = New Dictionary(Of Integer, String)
NewList.Add(0, "newsvg.txt")
NewList.Add(1, Nothing)

Compressor.ModifyArchive("d:\temp\test.7z", NewList)

But this code does not - throws exception complaining about wrong password. As with above, the archive created is fine -- just that ModifyArchive has trouble with it.

Dim Compressor As New SevenZip.SevenZipCompressor
Compressor.EncryptHeaders = True

Compressor.CompressFilesEncrypted("d:\temp\test.7z", "password", {"D:\Temp\svg.txt", "D:\Temp\tmp.txt"})

Dim NewList = New Dictionary(Of Integer, String)
NewList.Add(0, "newsvg.txt")
NewList.Add(1, Nothing)

Compressor.ModifyArchive("d:\temp\test.7z", NewList, "password")

Feature Request : Detect if the archive is first volume in multi part rar archive.

Currently, SevenZipSharp doesn't detect if the archive is the first volume of the multi-part archive. In the case of RAR archives, it is necessary cause all parts have the file extension of ".rar".

Currently, I determine it using the file name of the archive.

bool isVolume =
sevenZipExtractor.ArchiveProperties.Any(x =>
	x.Name.Equals("IsVolume") && x.Value != null && x.Value.Equals(true));
if (isVolume)
{
	var split = fileInfo.FullName.Split('.');
	if (split.Length >= 3)
	{
		if (split[split.Length - 2].StartsWith("part"))
		{
			int.TryParse(split[split.Length - 2].Substring(4), out var volumeNumber);
			if (volumeNumber != 1)
			{
				throw new Exception("Not the first volume of the archive.");
			}
		}
	}
}

Is it possible add a feature using file headers (Volume Number under Main Archive Header) that can tell us if the current archive is the first volume or not?

How to extract multiple files without using disk

Hi

I'm creating an Azure Function to unpack a password protected self-extracting file (.exe, but archive type is rar) from a FtpServer. I'm actually using the NuGet package shaman.SevenZipSharp (antiufo-fork), but it uses pretty much the same code (except for a few bug-fixes and .Net standard support).

I get an "Cannot access a closed file" when trying the following:

public IEnumerable<(Stream FileStream, string FileName)> PreprocessFtpFileStream(Stream fileStream, string orgFileName, BankSettings bankSettings)
        {
            var extractor = new SevenZipExtractor(fileStream, bankSettings.FilePassword);
            var files = extractor.ArchiveFileData;

            foreach (var entry in files)
            {
                var stream = new MemoryStream();
                extractor.ExtractFile(entry.Index, stream); //Error happens here

                yield return (stream, entry.FileName);
            }
        }

As far as I can tell from the source-code the error happens because extractor.ArchiveFileData disposes the underlying stream (calling InitArchiveData(true) which in turn calls GetArchiveInfo(true)).

So how do you extract all files in an archive and return data without writing them to disk first using ExtractArchive/ExtractFiles?

unimplemented and slow extraction of solid archives containing many entries

public void ExtractFiles(ExtractFileCallback extractFileCallback)
{
DisposedCheck();
InitArchiveFileData(false);
if (IsSolid)
{
	// solid strategy
}
else
{

I commented the first branch, so that it always uses the implementation for non solid, but:

I've been trying to extract all files from some solid 7z files, it's fast at first but the further it gets the slower it gets, slows to almost stopped, takes 6 hours instead of 1 minute or so because of this.

It's doing a triangle.

ExtractFile(Index, Stream);

exhibits the same slowdown

Unable to load native library

I am trying to use the latest SevenZipSharp version from NuGet (currently 1.2.231).

My code looks like this:

SevenZipBase.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");

using (var archive = new SevenZipExtractor(inputFile))
{
    archive.ExtractArchive(outputPath);
}

The file 7z.dll is present on the specified path; it is my local (flawlessly working) 7zip installation.

On the line starting with using, the following exception is thrown:

SevenZip.SevenZipLibraryException: Can not load 7-zip library or internal COM error! Message: failed to load library from "C:\Program Files\7-Zip\7z.dll".
bei SevenZip.SevenZipLibraryManager.LoadLibrary(Object user, Enum format)
bei SevenZip.SevenZipExtractor.Init(String archiveFullName)
bei SevenZip.SevenZipExtractor..ctor(String archiveFullName)

Note that this also happens if I point to the very DLL file found in this repo (7z64.dll). Also, the message is different from the one when the file really doesn't exist.

What am I missing?

rar4-sfx support

Hi! After adding rar5 format support, you renamed rar to rar4 but forget to add in self extracting archives recognition block in FileChecker.CheckSignature. Please add "InArchiveFormat.Rar4," in FileChecker.cs row 174. Thanks!

Does not work with .tar.gz and .tar.bz2?

Thanks for the great library.

I am having some problems with it. I tried to read .tar.gz and .tar.bz2 files but it comes with wrong data. It shows only 1 file in the archive "[no name]".

You can download the example file from here.

I also tried the same file with SevenZipLib and it works fine.

Duplicated files & directories appear when it appends by CompressDirectory method.

For example:
var arcFullName = @"C:\blablabla.7z";
var dirFullName = @"C:\Tmp\ForPacking"; //include file "test.txt"
var cmpr = new SevenZipCompressor();
cmpr.CompressionMode = File.Exists(arcFullName) ? CompressionMode.Append : CompressionMode.Create;
cmpr.PreserveDirectoryRoot = true;
cmpr.CompressDirectory(dirFullName, arcFullName);
1st run -> create archieve file "c:\blablabla.7z" with "ForPacking\test.txt"
2nd run -> archieve file "c:\blablabla.7z" consist of directory "ForPacking" with two files "test.txt" !?
What's wrong?

SevenZipCompressor Compressing callback returning significantly wrong progress

I am not sure if this is an issue with sevenzipsharp or the 7z.dll (I am using one from 7z 19.00), but when I subscribe to the Compressing event, when I inspect the argument's PercentDone value, it seems to be wildly off. It will go from 0-100 very quickly (for a 2GB source directory I am compressing), in which I believe it is filling buffers. After this reaches 100%, I get no more progress notifications until the archive job is complete - which can take several minutes.

When I use 7zip gui to compress this archive, I see correct progress, so I am wondering if maybe the compression callback is binded to the wrong interface to the dll? It shows bytes written going all the way up to the 2GB of data, but it seems more like that's what's read and not what's actually been processed, as my process sits at 14GB of memory for almost 3 minutes until the archive is done being generated.

My code to generate an archive:

var compressor = new SevenZip.SevenZipCompressor();
compressor.CompressionLevel = CompressionLevel.Ultra;
//compressor.CustomParameters.Add("s", "on"); //can't figure out how to make it do solid archives
compressor.Compressing += (a, b) =>
{
    Debug.WriteLine(b.PercentDone);
    mainWindow.UpdateBusyProgressBarCallback(new ProgressBarUpdate(ProgressBarUpdate.UpdateTypes.SET_VALUE, (int)b.PercentDone));
};
compressor.FileCompressionStarted += (a, b) => { Debug.WriteLine(b.FileName); };
compressor.CompressFileDictionary(archiveMapping, archivePath);
compressor.CompressionMode = CompressionMode.Append;
compressor.CompressionLevel = CompressionLevel.None;
compressor.CompressFiles(archivePath, new string[]
{
    Path.Combine(ModBeingDeployed.ModPath, "moddesc.ini")
});
Utilities.HighlightInExplorer(archivePath);

After doing some investigation, it seems the process for archive compression works like this;

  1. Read source files into memory (this is what the Compressing % callbacks show)
  2. 7z.dll does it's thing with the file for significant amount of time
  3. 7z.dll/SevenzipWrapper write the new memory-archive to disk. I can see bytesWritten being raised but it is not being passed back to the sevenzipcompressor it seems (or maybe I missed something).

It is step 2 that would be most useful. I am looking into seeing how it is done in 7z UI, maybe it is exposed via some sort of interface.

Custom parameters not work

can't use this parameters:
compressor.ArchiveFormat = OutArchiveFormat.Zip;
compressor.CompressionMethod = CompressionMethod.Ppmd;
compressor.CompressionLevel = CompressionLevel.Ultra;
compressor.Compressing += status;
compressor.CustomParameters.Add("mem", "128M");
compressor.CustomParameters.Add("o", "12");

Get this error: Execution has failed due to an internal SevenZipSharp issue (0x80070057).

Extracting from stream fails for Zip format

Hello, this can be reproduced in ExtractionFromStreamTest():

//var bytes = File.ReadAllBytes(@"TestData\multiple_files.7z");
var bytes = File.ReadAllBytes(@"TestData\zip.zip");

Running on Linux (.Net Core)

Now that SevenZipSharp support .Net Std. will it then be running in .Core on Linux too?
I'm seeing an issue with the 7zip.dll...are there an equivalent Linux library that can be used?

not responding

var extractor = new SevenZipExtractor(@"test.rar");
for (var i = 0; i < extractor.ArchiveFileData.Count; i++)
{
extractor.ExtractFiles("bb", extractor.ArchiveFileData[i].Index);
}

not responding at last file?

myx not supported due to missing conversion to int in SevenZipCompressor

I am trying to compress an archive and I have been using the Ultra compression setting. I am porting code from an old program that used 7z on the command line with a -md=256m (which is 2^28). mx9 (ultra) is only 64MB dictionary, which when compressing my archive is the difference between a 29MB (256MB dictionary) archive and a 59MB archive (64MB dictionary)

I have tried compressor.CustomParameters.Add("d", "28") but I get an invalid argument exception when the properties are set to the 7z binded dll. The d parameter is converted to an int so I can't use 256m for example. I can't find any tests or anything in the code for this project on how to use a custom dictionary size, which is really important for the kind of work that I am doing.

Anyone know how to do that? (I am using 7z LZMA).

My issue was that myx was not implemented. After doing some debugging it is due to the parameter binding not being cast to int before binding (instead binding as string).

https://github.com/squid-box/SevenZipSharp/blob/dev/SevenZip/SevenZipCompressor.cs#L313

On this line if you add a || pair.Key == "yx" on the end it fixes it. I might put a in a PR when I have time (I have a custom version of this library in my project so it takes more effort to put a PR back).

Once casted to an integer, yx works.

Use IDictionary instead of Dictionary for increased flexibility

Using IDictionary as parameter to CompressStream|FileDictionary would give us the possbility to pass a SortedDictionary or ConcurrentDictionary directly to those methods.

I have a feature branch - #41 - with the proposed changes. Please review and let me know if you find it useful.

ExtractArchive decided wrong format

Hi,

I am using sevenzipsharp and I have a lot of archives that are msi, rar, iso and more formats that ExtractArchive decided it is TAR and because of that failed to extract them.
The archives can be extracted via the 7zip gui.
So I am sure the archives are OK.
Edited : some msi and rar extracted OK via the ExtractArchive but lot of Tham are failing.

Unable to extract SFX/Packed executables

Summary

Squid-Box.SevenZipSharp cannot extract some SFX archives or packed executables.
Ex) cloc-1.80.exe

Details

First, thanks for your effort to maintain such a great library.
SevenZipSharp can extract files from 7zip's own SFX archive, but it cannot from third-party packed executable (e.g. installer, perl-runtime-packaged exectuable) which 7zip executable can extract.

Files can be extracted with SevenZipSharp

  • 7zip's official installer - 7zip SFX archive

Files cannot be extracted with SevenZipSharp

  • cloc's Windows binary - Packed with Perl runtime

7zip executable can open cloc binary's inside, and when I see its property 7zip detects its format as zip while SevenZipSharp's internal file format detector results in InArchiveFormat.PE. I performed some tests to find proper InArchiveFormat for this file, but no single format was unable to extract that file, including InArchiveFormat.Zip.

Tested Environment

  • OS : Windows 10 v1809 x64
  • Runtime : .Net Framework 4.7.2
  • 7zip : v18.06, v19.00
  • SevenZipSharp : v1.1.136

Struggling to get started with SevenZipSharp - Suggestions?

Hi everyone,
I am having some issues to start using SevenZipSharp, may I ask you for help?
Otherwise, is there any tutorial to get started with SevenZipSharp?

I'd like to create a SFX file, but I am struggling to get started with SevenZipSharp. Here, my code:

var sfx = new SevenZipSfx();
SevenZipCompressor tmp = new SevenZipCompressor();
using (MemoryStream ms = new MemoryStream())
{
    tmp.CompressDirectory(@"d:\Temp\", ms);
    sfx.MakeSfx(ms, @"d:\Temp\test.exe");
}

When this code is ran, CompressDirectory method throws this exception:

{"Could not load file or assembly 'System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The specified file could not be found.":"System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"}

I did some googling and, as far as I understood, it seems that 7z.dlls are missing. Hence, I tried to add those reference and also use SeveZipSharp.Interop Nuget, but without success.
Can anyone point me in the right direction, please? Any help will be really appreciated.

Best regards,
Lore

P.S. I also tried to run tests from repository project, but without success. In fact, there is a "testhost.dll" missing error; the solutions provided on stackoverflow were not successful.

High memory use and hang on large archives with current versions of 7Z.dll

I have a simple program that extracts entire archives of 7zip files. The archives contain video files so they tend to be large. My test archive is about 700MB and contains 119 video files. During testing, this simple loop:

for (var i = 0; i < extractor.ArchiveFileData.Count; i++)
{            
    extractor.ExtractFiles(BaseDirClass, extractor.ArchiveFileData[i].Index);
 }

extracted 28 files and consistently hung on the 29th file. Memory utilization climbed to about 500MB (working set) before hang. Hang occurs at the same spot using 32-bit or 64-bit and also occurs when running from the command line or within the VS debugger. I tried ExtractALL
(i.e. extractor.ExtractArchive(BaseDirClass);) and got the same result at the same spot but the Working set shot up to about 2GB before the hang. Poked around a bit and determined that the problem appeared to be 7z.dll. I was using V19.0 of 7z.dll. Just for kicks, I tried 7za.dll and 7zxa.dll - same results. I then backpedaled a bit and tried V18.5 and got the same results. I gave it one more shot with V16.4 of 7z.dll and that worked just fine. The working set never got above 110MB.

Probably not much you can do about this but I thought I'd post this in case someone else runs into the same issue.

Which versions of 7z.dll are supported?

I would like to upgrade to the latest version of SevenZipSharp and the underlying 7z.dll, but I am not sure which version of the DLL to use (or where to get a suitable version from).

  • There is a version in this SevenZipSharp repository, but it is two years old.
  • There is a download for the latest version on the original 7zip website (labeled "7-Zip Extra: standalone console version, 7z DLL, Plugin for Far Manager"), but that one only contains 7za.dll and I don't really want support for "only 7zip archives".
  • I could take the 7z.dll out of my local 7zip (application) installation, but that feels somehow "wrong" and makes me wonder whether there isn't an official, dedicated way to download the DLL for redistribution.

I have an exception in SevenZipExtractor.BeginExtractArchive(string directory) when unpacking a stream

       var zipStream = new FileStream("c:\\backup\\file.zip", FileMode.Open);
            SevenZip.SevenZipBase.SetLibraryPath("x86\\7z.dll");
            var z = new SevenZip.SevenZipExtractor(zipStream, "pass");
                 z.BeginExtractArchive("c:\\tmp\\test_ext");

.net 4.5.2

The specified stream can not seek or read.
Имя параметра: stream

Server stack trace:
в SevenZip.SevenZipExtractor.ValidateStream(Stream stream) в C:\projects\SevenZipSharp\SevenZip\SevenZipExtractor.cs:строка 691
в SevenZip.SevenZipExtractor.Init(Stream stream) в C:\projects\SevenZipSharp\SevenZip\SevenZipExtractor.cs:строка 100
в SevenZip.SevenZipExtractor.RecreateInstanceIfNeeded() в C:\projects\SevenZipSharp\SevenZip\SevenZipExtractorAsynchronous.cs:строка 36
в SevenZip.SevenZipExtractor.DisposedCheck() в C:\projects\SevenZipSharp\SevenZip\SevenZipExtractor.cs:строка 352
в SevenZip.SevenZipExtractor.ExtractArchive(String directory) в C:\projects\SevenZipSharp\SevenZip\SevenZipExtractor.cs:строка 1270

Execution has failed due to an internal SevenZipSharp issue (0x8007000e)

A exception is throw when we want to compress a large number of files (900 files - approximately 1Mo Each)

This is the stack trace :

at SevenZip.SevenZipBase.ThrowException(CallbackBase handler, Exception[] e) at SevenZip.SevenZipBase.CheckedExecute(Int32 hresult, String message, CallbackBase handler) at SevenZip.SevenZipCompressor.CompressStreamDictionary(IDictionary'2 streamDictionary, Stream archiveStream, String password) at SevenZip.SevenZipCompressor.CompressFileDictionary(IDictionary'2 fileDictionary, Stream archiveStream, String password) at SevenZip.SevenZipCompressor.CompressFileDictionary(IDictionary'2 fileDictionary, String archiveName, String password)

  • release number : 1.2.184.0
  • 7z version used : 18.5.0.0 (64bits)
  • OS : Windows Server 2012 R2 (EN - 64 bits)

The working workaround is to do a compression call each 100 files.

Issue with compressing event & deflate

Ok, so I'm not sure if I'm a complete idiot or if this is a bug, but I was testing some compression out with a progress bar using the compression event and I discovered that deflate & deflate64 with the Zip OutArchiveFormat do not activate the compression event. (Using Ultra Level) It works with all the other compression formats and methods are far as I can tell.
Code for event:
sevenZipCompressor.Compressing += (sender, args) =>
{
Console.WriteLine("Should be activated."); //Isn't activated at all
progress.Report(args.PercentDone);
};
I'm using the SevenZipCompressor.CompressDirectory(); method.

EDIT:
Ok, so it appears that it works while compressing files (SevenZipCompressor.CompressFiles();), but not with the compress directory method.

Can't use custom parameter "d"

As part of fixing #82, I've found that the "d" parameter (see documentation for uses) also doesn't work. The solution to #82 has not resolved this one, so I'm adding it here as a Known Issue.

The unit test SevenZipCompressorTests.CompressWithCustomParameters_BZip2 exposes this bug, but is marked as a warning for now.

This snippet shows the issue:

var compressor = new SevenZipCompressor
{
    ArchiveFormat = OutArchiveFormat.Zip,
    CompressionMethod = CompressionMethod.BZip2
};

compressor.CustomParameters.Add("d", "900000");
compressor.CompressFiles("path_to_archive, "path_to_file(s)_to_compress");

Unable to extract a 7z SFX exe archive from memory

I have been working with this for an updater for my mod manager and have noticed a few things.

  1. The SFX signature detection size is too small at just 256KB. While this will work for some apps, in mine for example, I install an icon, which makes my SFX header larger than 256KB. I set mine to 1MB and I can find a 7zip SFX. This is at the top of File Checker.
  2. If I download an exe to memory for this SFX, and then try to extract it from a memorystream (using new SevenZipExtractor(memorystream)), the Check() method is executed because it thinks it's an executable. This method seems to be designed for file-based extraction as it closes the archive stream, which is my memory stream. Thus, when I try to actually extract the files, it dies because the memory stream was closed. This is part of SevenZipExtractor.cs's Check() method. I am not sure how to work around this unless I check if it's a memory based stream (vs a filestream).
            finally
            {
                if (_archive != null)
                {
                    _archive.Close();
                }
                ((InStreamWrapper)_archiveStream).Dispose(); <-- This disposes the input stream.
                _archiveStream = null;
                _opened = false;
            }
            return true;

In my app (I have SevenZipSharp source) I changed the GetArchiveStream call in Check() to see if it's an emulationstreamproxy, and then checked if that source is a memorystream - if it is, don't close the stream. I will test this implementation to see if it's an working solution for other archive types. I try to get the test framework up and running and also add cases to test against memory-loading and extraction.

Dual License?

Would you consider licensing under LGPL also? GPL 3 is a bit more restrictive than my company is willing to allow.

Possible to extract files in solid archive to streams via callback?

I work frequently with solid archive for distribution of mods for the Mass Effect series. Solid compression significantly reduces distribution sizes, so all mods are typically deployed using solid 7z, and the source files are uncompressed (game files support their own individual file compression, we do not distribute them this way to let 7z do more compression during transfer).

I am working to getting our per-file compression working, and it can take a stream to load a file in which is then fed to the compressor. I'm wondering if there's a way to fetch the output stream of a solid-archive extraction. I see this is possible, but not for solid archives. I understand how solid archives work (not the decompression of it though), so I'm wondering if this is possible. When I call extraction on the solid archive, I feed a list of indices to extract as sometimes I do not want the entire archive.

I can extract to disk and compress that instead, which is an alternative I could do. I would just like to reduce the disk I/O if possible by feeding the memory stream to my fileformat parsing which can then compress it as it extracts onto the disk.

SFX creation doesn't work

See Unit test CreateSfxArchiveTest.

Running the test runs into a problem:

System.ArgumentNullException : Value cannot be null.
Parameter name: src
   at SevenZip.SevenZipSfx.WriteStream(Stream src, Stream dest) in D:\Git\GitHub\SevenZipSharp\SevenZip\SevenZipSfx.cs:line 362
   at SevenZip.SevenZipSfx.MakeSfx(Stream archive, Dictionary`2 settings, Stream sfxStream) in D:\Git\GitHub\SevenZipSharp\SevenZip\SevenZipSfx.cs:line 432
   at SevenZip.SevenZipSfx.MakeSfx(Stream archive, String sfxFileName) in D:\Git\GitHub\SevenZipSharp\SevenZip\SevenZipSfx.cs:line 383
   at SevenZipTests.MiscellaneousTests.CreateSfxArchiveTest() in D:\Git\GitHub\SevenZipSharp\SevenZipTests\MiscellaneousTests.cs:line 80```

Need to make a reference to System.Configuration.ConfigurationManager etc.

There are at least these three nuget packages references in the project
System.Configuration.ConfigurationManager
System.Security.Cryptography.ProtectedData
System.Security.Permissions

For just to compress a file I need to make a reference to System.Configuration.ConfigurationManager in my .net std. 2.0 project.
System.Security.Cryptography.ProtectedData seem to have two dll's by the same name, one is located in a subfolder(\runtimes\win\lib\netstandard2.0)....do I need both? It a little messy to distribute.
I expected I only had to make a reference to SevenZipSharp.dll in my own project.
If it cannot be solved be changing the code then what about adding it (or all three/four) as dependencies in the Nuget package. Perhaps even add 7z.dll as a dependency.

Not that I like to use Nuget myself, but at least I can see which additional dll's I need to get into my project.

SevenZipExtractor exception when attempting to read from a .zip archive.

SevenZip.SevenZipArchiveException: 'Invalid archive: open/read error! Is it encrypted and a wrong password was provided?
If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake.'

This error has been consistently reproduced in 3 different .zip archives. Not sure what to make of this. The files are not password protected, not corrupted and are not locked by another process.

When extracting single file from archive "FileExtractionStarted", "Extracting" and "FileExtractionFinished" event show all files extracting.

This seems like a bug to me but maybe it's just my lack of understanding how it should work. When I try to extract a single file the library seems to process the entire archive rather than just the single file. In my case I have an archive with one very large file and a bunch of little texts files (10). I try to extract one of the small text files and I have the "FileExtractionStarted" event fire 11 messages (one for each file in the archive) instead of just one total. That also means the "FileExtractionFinished" event fires 11 times and the "Extracting" event fires an excessive amount of times as well (once by percent update but for each file)!

Using 7zipFM I can extract the single file in a few milliseconds. Using this method it takes about 30 seconds. This becomes a huge problem when I use the same method to extract almost all the files. It then sends a "FileExtractionStarted" event for each file in the archive during EACH file actually being extracted!

I'm using the following code...

private void SevenZipExtractor_Extracting(object sender, ProgressEventArgs e)
{
  //Only update every 20%
  if (e.PercentDone % 20 == 0)
    System.Diagnostics.Debug.WriteLine("SevenZipExtractor_Extracting -- " + e.PercentDone + "%");
}

private void SevenZipExtractor_FileExtractionFinished(object sender, FileInfoEventArgs e)
{
  System.Diagnostics.Debug.WriteLine("SevenZipExtractor_FileExtractionFinished -- " + e.PercentDone + "% Filename:" + e.FileInfo.FileName);
}

private void SevenZipExtractor_FileExtractionStarted(object sender, FileInfoEventArgs e)
{
  System.Diagnostics.Debug.WriteLine("SevenZipExtractor_FileExtractionStarted -- " + e.PercentDone + "% Filename:" + e.FileInfo.FileName);
}

private void DecompressThread(string archiveFilePath, string localPath)
{
  //archiveFilePath is the path of the 7z archive
  //localPath is the path of the newly extracted text file from the 7z archive
  
  byte[] fileInBytes = File.ReadAllBytes(archiveFilePath);
  using (MemoryStream inStream = new MemoryStream(fileInBytes))
  {
    using (SevenZipExtractor extractor = new SevenZipExtractor(inStream))
    {
      extractor.Extracting += SevenZipExtractor_Extracting;
      extractor.FileExtractionStarted += SevenZipExtractor_FileExtractionStarted;
      extractor.FileExtractionFinished += SevenZipExtractor_FileExtractionFinished;
      using (FileStream file = new FileStream(localPath, FileMode.Create, FileAccess.Write))
      {
        //Extract a single file
        // I know and have checked the extractor.ArchiveFileData[4] data
        // to ensure it's the small text file I want to extract
        extractor.ExtractFile(4, file);
      }
      extractor.Extracting -= SevenZipExtractor_Extracting;
      extractor.FileExtractionStarted -= SevenZipExtractor_FileExtractionStarted;
      extractor.FileExtractionFinished -= SevenZipExtractor_FileExtractionFinished;
    }
  }
}

Here are the results of the events I get from the Library (results_of_archive_extraction.txt). It seems to extract the single text file as I would expect but when doing so is VERY slow because it tries to process the entire file instead of just the one file.

I have a question opened on stackoverflow with more information. It refers to the SevenZipSharp.Interop NuGet that uses the same process your library uses. I get the same result with your library as well.

Coveralls.io not getting coverage reports

To quote AppVeyor:

Error 422 sending to coveralls.io: Unprocessable Entity
 - Error code 422 indicate a problem with your token. Use the --debug option for more details.

Excessive garbage collection during extraction

Hello, @squid-box! I've notified huge performance degradation in case of a lot of small compressed files. Huge archive with real data (32gb uncompressed, 250k mostly small entries, something like compressed hard disk image) decompression is 4-12 times slower than with regular 7z.FM.exe, the main reason is excessive GC.Collect call in ArchiveExtractCallback.SetOperationResult (line 462) for each file. Test runs on such files show that ~70% of extraction time was spend in GC.Collect() call in our test case, our custom code allocates ~10kb of objects per second and 30-200 GC calls per second makes app suffer.
You can easily reproduce it with a lot of simple text files in one archive, I can send such if necessary.
Anyway it's weird that library collects garbage while it should be on application side, I've checked unzipping without GC calls and with different 7z archive content type and everything ok.

Probably reason of #46 is the same ArchiveUpdateCallback.SetOperationResult (line 709).

Thanks!

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.