GithubHelp home page GithubHelp logo

adamhathcock / sharpcompress Goto Github PK

View Code? Open in Web Editor NEW
2.2K 96.0 474.0 15.06 MB

SharpCompress is a fully managed C# library to deal with many compression types and formats.

License: MIT License

C# 72.27% C++ 26.61% Makefile 0.13% HTML 0.99%
c-sharp dotnet-core unrar zip bzip2 tar gzip compression lzip lzma

sharpcompress's Introduction

SharpCompress

SharpCompress is a compression library in pure C# for .NET Framework 4.62, .NET Standard 2.1, .NET 6.0 and NET 8.0 that can unrar, un7zip, unzip, untar unbzip2, ungzip, unlzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip/lzip are implemented.

The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).

GitHub Actions Build - SharpCompress Static Badge

Need Help?

Post Issues on Github!

Check the Supported Formats and Basic Usage.

Recommended Formats

In general, I recommend GZip (Deflate)/BZip2 (BZip)/LZip (LZMA) as the simplicity of the formats lend to better long term archival as well as the streamability. Tar is often used in conjunction for multiple files in a single archive (e.g. .tar.gz)

Zip is okay, but it's a very hap-hazard format and the variation in headers and implementations makes it hard to get correct. Uses Deflate by default but supports a lot of compression methods.

RAR is not recommended as it's a propriatory format and the compression is closed source. Use Tar/LZip for LZMA

7Zip and XZ both are overly complicated. 7Zip does not support streamable formats. XZ has known holes explained here: (http://www.nongnu.org/lzip/xz_inadequate.html) Use Tar/LZip for LZMA compression instead.

A Simple Request

Hi everyone. I hope you're using SharpCompress and finding it useful. Please give me feedback on what you'd like to see changed especially as far as usability goes. New feature suggestions are always welcome as well. I would also like to know what projects SharpCompress is being used in. I like seeing how it is used to give me ideas for future versions. Thanks!

Please do not email me directly to ask for help. If you think there is a real issue, please report it here.

Want to contribute?

I'm always looking for help or ideas. Please submit code or email with ideas. Unfortunately, just letting me know you'd like to help is not enough because I really have no overall plan of what needs to be done. I'll definitely accept code submissions and add you as a member of the project!

TODOs (always lots)

  • RAR 5 decryption crc check support
  • 7Zip writing
  • Zip64 (Need writing and extend Reading)
  • Multi-volume Zip support.

Version Log

Version 0.18

Version 0.17.1

Version 0.17.0

Version 0.16.2

Version 0.16.1

Version 0.16.0

Version 0.15.2

  • Fix invalid headers - fixes an issue creating large-ish zip archives that was introduced with zip64 reading.

Version 0.15.1

Version 0.15.0

Version 0.14.1

Version 0.14.0

Version 0.13.1

Version 0.13.0

  • Breaking change: Big refactor of Options on API.
  • 7Zip supports Deflate

Version 0.12.4

  • Forward only zip issue fix #160
  • Try to fix frameworks again by copying targets from JSON.NET

Version 0.12.3

  • 7Zip fixes #73
  • Maybe all profiles will work with project.json now

Version 0.12.2

  • Support Profile 259 again

Version 0.12.1

  • Support Silverlight 5

Version 0.12.0

  • .NET Core RTM!
  • Bug fix for Tar long paths

Version 0.11.6

  • Bug fix for global header in Tar
  • Writers now have a leaveOpen bool overload. They won't close streams if not-requested to.

Version 0.11.5

  • Bug fix in Skip method

Version 0.11.4

  • SharpCompress is now endian neutral (matters for Mono platforms)
  • Fix for Inflate (need to change implementation)
  • Fixes for RAR detection

Version 0.11.1

  • Added Cancel on IReader
  • Removed .NET 2.0 support and LinqBridge dependency

Version 0.11

  • Been over a year, contains mainly fixes from contributors!
  • Possible breaking change: ArchiveEncoding is UTF8 by default now.
  • TAR supports writing long names using longlink
  • RAR Protect Header added

Version 0.10.3

  • Finally fixed Disposal issue when creating a new archive with the Archive API

Version 0.10.2

  • Fixed Rar Header reading for invalid extended time headers.
  • Windows Store assembly is now strong named
  • Known issues with Long Tar names being worked on
  • Updated to VS2013
  • Portable targets SL5 and Windows Phone 8 (up from SL4 and WP7)

Version 0.10.1

  • Fixed 7Zip extraction performance problem

Version 0.10:

  • Added support for RAR Decryption (thanks to https://github.com/hrasyid)
  • Embedded some BouncyCastle crypto classes to allow RAR Decryption and Winzip AES Decryption in Portable and Windows Store DLLs
  • Built in Release (I think)

XZ implementation based on: https://github.com/sambott/XZ.NET by @sambott

XZ BCJ filters support contributed by Louis-Michel Bergeron, on behalf of aDolus Technology Inc. - 2022

7Zip implementation based on: https://code.google.com/p/managed-lzma/

LICENSE Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sharpcompress's People

Contributors

4ybaka avatar adamhathcock avatar benshoof avatar bond-009 avatar catester avatar coderb avatar dannyboyk avatar dependabot[bot] avatar ds5678 avatar erior avatar frabar666 avatar haykpetros avatar hrasyid avatar iamcarbon avatar ingbertolini avatar itn3000 avatar kenkendk avatar larvata avatar louis-michelbergeron avatar markfinal avatar martindembergerr9 avatar mattkotsenas avatar nanook avatar ownageismagic avatar sander2 avatar turbedi avatar twanvandongen avatar twirpx avatar vladimdemidov avatar vpenades 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  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

sharpcompress's Issues

TransferTo extension method not found

Having grabbed the Nuget version. Im getting a "TransferTo" exception trying to unrar a rar file. I says the extension method doesn't exist. I have add using:
using SharpCompress.Common;
using SharpCompress.Reader;
using SharpCompress.Reader.Rar;

Thanks for any help.

ZipWriter can't create a directory entry

I am unable to create a directory entry with ZipWriter. If I am not missing, I think this is a serious drawback for such a great library. Can you please include this enhancement? In the meantime, is there any workaround if I am not building from source?

Writing zero length files to a ZIP causes a crash

Trying to add a zero length file to a ZIP file causes the library to crash. A crude fix is as follows:

In CBZip2OutputStream.cs

    private void MainSort()
    {
        int i, j, ss, sb;
        int[] runningOrder = new int[256];
        int[] copy = new int[256];
        bool[] bigDone = new bool[256];
        int c1, c2;
        int numQSorted;

        /*
        In the various block-sized structures, live data runs
        from 0 to last+NUM_OVERSHOOT_BYTES inclusive.  First,
        set up the overshoot area for block.
        */

        last = last == -1 ? 0 : last;       // PRT: Prevent crash on zero length files

Cheers,
Paul

Self extracting exe

From what I can tell, self extracting zip archives are not supported. I just wanted to check it's not something I am doing wrong.

If I try to open one for reading, I get NotSupportedException: Unknown header: 9460301.

Are there any plans to support them?

.NET Core 4.5 assembly is not strong named in the NuGet Package

In the 0.10.1.3 version of the NuGet package, the .NET 4 and PCL assemblies are strong named, but the .NET Core 4.5 assembly is not.

This is causing an assembly loading failure in my Windows 8.1 App project because I'm using another PCL package that depends on SharpCompress. When I install that other library, NuGet brings SharpCompress along as a dependency, and installs the .NET Core 4.5 version instead of the PCL version. Then at runtime, that other library fails to load SharpCompress because the .NET Core 4.5 SharpCompress assembly is not strong named, but the other package is bound to the strong named PCL version.

Update NuGet Package

Could you upload new version of sharpcompress to nuget? The version on nuget is one year ago and didn't contain support for decompress rar archive with password.

Help with crc property

Sorry about my english

I'm trying to get the CRC32 of a file ownership. However, the return shows a wrong result. here's the code

Stream stream = File.OpenRead(@"C:\Test.rar");
var reader = ReaderFactory.Open(stream);
while(reader.MoveToNextEntry())
{
Label1.Content = reader.Entry.Crc.ToString();
}

The RAR file has only one file inside to test.
This code prints this value on label 4263732290 as if CRC

In Winrar, the value pointed to as CRC is FE236442, which is the same value I get when I calculate the uncompressed file.

then used the SevenZipSharp with the following code

SevenZipCompressor.SetLibraryPath(@"C:\7z.dll");
SevenZipExtractor zip = new SevenZipExtractor("Test.rar");
Label1.Content = zip.ArchiveFileData[0].Crc.ToString();

To my death, I got the same result (4263732290).
Is there something I'm doing wrong? I need to do another treatment with the warmth of the property to extract the calculation of CRC32??

Another thing I noticed in testing is that the other properties return the correct value (FilePath, CompressedSize, Size) everything works perfectly, minus the CRC32

Thanks for the help

Windows Phone SL 8.1 certification failing

With the latest nuget package 0.11.0 the Windows Phone Silverlight 8.1 certification is failing saying it contains "Debug" version of the sharpcompress,dll. Is it possible to update the nuget package with the "Release" version anytime soon please?

Also it seems that the zip directory listing does not obey the character encoding in the names... how to use UTF8 so that all entry names appear correct?

Consider use of branches for different NET-runtime versions

My goal is to have NET3.5-targeted project with tests.
Afaik, Microsoft unit test projects require NET3.5 or newer. SharpCompress.NET2 is easily upgradeable to 3.5 (just remove LinqBridge and target 3.5).
The problems with different runtime versions had arosed, when I cloned the SharpCompress.Test to target NET3.5. Some of those problems are, for example: optional parameters, absence of some IO.Directory methods, IEnumerable<T> is not covariant.

So, can we replace preprocessor-directives style of code with project-by-framework style?
We can use different branches to simplify support. What do you think?

As a side note, do we really need to support NET2 version? Windows 7 and newer (client) and Windows 2008 R2 SP1 (server) are shipped with NET 3.5.

NUGET package is wrong

Not sure what happened with the packaging but the same assembly has been packaged into all three locations in the 0.10.1.1 nuget package.

Looking in ILSpy I see that the portable one is

[assembly: TargetFramework(".NETCore,Version=v4.5", FrameworkDisplayName = ".NET for Windows Store apps")]

whereas it should be something like

[assembly: TargetFramework(".NETPortable,Version=v4.0,Profile=Profile1", FrameworkDisplayName = ".NET Portable Subset")]

File names get truncated at 40 characters

Hi,

I'm facing this weird issue where the file names are getting truncated at 40 characters. I tried using the TarNames branch but it didn't solve the issue. I'm using a .tgz file with several directories and file names are guids.

Is there a fix to this issue?

TarArchive seems to hold onto resources

Creating a new TarArchive seems to hold on to resources after disposing of it.

            var temp = Path.Combine(ThisLocation, Path.GetRandomFileName());
            CopyFiles(TheItems, temp);

            var newTarball = Path.Combine(ThisLocation, "MyTarBall.tgz");
            using (var archive = TarArchive.Create())
            {
                archive.AddAllFromDirectory(temp);
                archive.SaveTo(newTarball, CompressionType.GZip);
            }

            //An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code
            //Additional information: The process cannot access the file 'New Text Document.txt' because it is being 
            //used by another process.
            Directory.Delete(temp, true);

The sample to repro is here:
https://github.com/TheAngryByrd/SharpCompressHoldingOntoFiles/

Thanks!

Delegates/event handlers for feedback when creating zip files.

I'm zipping lots of large files (10GB+) and need to be able to get some information back on how it's doing. Is it possible to get some delegates in place to be able to find out how quickly my file is zipping (bytes read, bytes zipped, current size, files added etc)? It would be really useful for providing feedback to clients waiting for their documents!

Z_DATA_ERROR. reading crypted zip on WP81 but ok on Android.Xamarin

Hi, I'm using SharpCompress.Portable in a PCL-project targeting Android-Xamarin and Windows Store App WP81 to read files from crypted zips. Everything works fine in Android, but same code, same zip gives problems in InflateManager.Inflate(FlushType flush):

case InflateManagerMode.BLOCKS:
r = blocks.Process(r);

r is often ZlibConstants.Z_DATA_ERROR.

Any ideas why?
Thanks, Tom

Extract rar with invalid password does not raise exception

Hello, when I extract a rar file with password everything works as expected if the password is ok. However, when the password is wrong the extraction runs without raising any exception and the files are extracted. Of course the files are corrupted. This is the code I am using:

string password = "wrongpass";
string inpath = @"D:\Test\File_with_pass.rar";
RarArchive rar = RarArchive.Open(inpath, SharpCompress.Common.Options.LookForHeader, password);
rar.WriteToDirectory(@"D:\Test\out");
rar.Dispose();

Since we can not ensure that the extraction went well, this issue is making the library useless for rar protected files.

Typo in ArchiveReader.cs will cause build to fail in all configurations except Debug

If you look at Line 246 in "SharpCompress\Common\SevenZip\ArchiveReader.cs" you will notice extra line that is causing build to fail in any build configuration other than Debug:

#if DEBUG
                            Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams +
#endif
 ")");
                        }

So it is necessary to remove Line 246 completely in order to fix this issue.

Problem Extracting 7z Archives

There is a problem when extracting small 7z files packed with ultra compression.
Exception: Data Error StackTrace: at SharpCompress.Compressor.LZMA.Decoder.Code(Int32 dictionarySize, OutWindow outWindow, Decoder rangeDecoder) in b:\Users\Hod\Documents\GitHub\sharpcompress\SharpCompress\Compressor\LZMA\LzmaDecoder.cs:line 357
get 7z file at: http://www.filedropper.com/mg83
inside there is a program.cs file that I used for test,
it uses the added option that I added in pull request for, but you can remove them.

Extracting multipart rar for Universal app

Hi,

I'm testing out creating Universal apps for Windows 10 and I'm trying to extract multipart rar files. It starts out fine but I'm getting error: "Multi-part rar file is incomplete. Entry expects a new volume: filename.ext". Extracting file with WinRAR is no problem, so there should not be any issues with my archive.

Here is my code:

using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        var archive = ArchiveFactory.Open(stream.AsStreamForRead());

                        foreach (var entry in archive.Entries)
                        {
                            if (!entry.IsDirectory)
                            {
                                _sourceAnalysis.Files.Add(entry.Key);

                                var entryStream = entry.OpenEntryStream();

                                var extractedFile = await _settings.SourceStorageFolder.CreateFileAsync(entry.Key,CreationCollisionOption.ReplaceExisting);

                                using (var outputStream = await extractedFile.OpenStreamForWriteAsync())
                                {
                                    await entryStream.CopyToAsync(outputStream);
                                }
                            }
                        }
                    }

Any ideas as to what might be wrong?

Name truncation in TarHeader will always throw ArgumentOutOfRangeException

The conditional check from lines 65 to 69 of SharpCompress.Common.Tar.Headers.TarHeader will always result in an ArgumentOutOfRangeException on line 67.

The signature is of substring is String.Substring(int startIndex, int length), but this line uses the length of the Name property as the length argument, instead of the difference between length and the start index.

Didn't think this needed it's own fork/merge because it's a one-liner, but I don't know if this usage appears anywhere else.

Add support for seeking with non-compressed RARs

It'd be nice if RARs with 0x30 (store) packing method could be seeked. That should work since that doesn't require any unpacking and can be read directly from disk. Some book keeping is needed though.

Incorrect code processing long filename (more than 100 symbols)

Hello.

We get exception when try to add files with names more than 100 symbols. System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at SharpCompress.Common.Tar.Headers.TarHeader.Write(Stream output)

Looks like next code is incorrect at TarHeader class

if (Name.Length > 100)
{
name = Name.Substring(101, Name.Length);
ArchiveEncoding.Default.GetBytes(name).CopyTo(buffer, 345);
}

Should be:

name = Name.Substring(101, Name.Length - 100); //??

LinqBridge

Could LinqBridge be removed?
It is a dependency on NuGet level that isn't needed, so why make a required reference between the two? If someone wants to use LinqBridge he can add the reference himself and use it. Sounds more logical than getting the reference and having to remove it manually when you don't want to use it... and added to that: when you don't want to use it you are still required to have the NuGet package because the reference is required, even though you are not using it.

compress to rar file

Hi, it's possible to compress to rar file using a password with sharpcompress???????

Short truncated decompress by BZip2Stream

Hi, I'm tested very large bzip2'ed stream decompress by BZip2Stream.

using (var fs = new FileStream(@"D:\planet-latest.osm.bz2", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    using (var cs = new BZip2Stream(fs, CompressionMode.Decompress))
    {
        using (var ts = new FileStream(@"D:\pp.osm", FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
        {
            cs.CopyTo(ts);
            ts.Close();
        }
    }
}

Data is OpenStreetMap's Planet.osm.bz2. (size=36GB)
Outputted pp.osm size is just 900000 bytes, of course may result 500GB over.

How can I decompress this file?
Thanks.

Password for sharpcompress.pfx file

Hi,

I downloaded sharpcompress to fix some issues. I tried to compile it but I can't because I need to give a password for the signing file. Can you tell me what password I need to use?

Greetings,
Kees van Spelde

Concurrency bug in testing

When you run tests first time, some tests fail. Then if you rerun unpassed tests, they will pass. Seems like a bug in concurrency

Convert Utility.WriteLittleEndian(...) method to be safe

It feels like WriteLittleEndian(...) method in Utility.cs file (lines 209 and 251) can be converted to managed code which will make SharpCompress project completely managed and won't require "Allow unsafe code" setting to be set:

public static unsafe void WriteLittleEndian(byte[] array, int pos, short value)
{
    fixed (byte* numRef = &(array[pos]))
    {
        *((short*)numRef) = value;
    }
}

Random access an encrypted multipart rar volume

Hei @adamhathcock
Thanks for sharing this project with us.
I'm trying to achieve some complicated stuff with rar and for that I have looked at number of unrar implementations (including the unrar code itself). Your implementation is by far the most advanced and best structured one ๐Ÿ‘ .

What I'm trying to achieve:

  • Let's assume I have a multivolume rar archive which contains at least one big file (splitted).
  • The file in the archive might be encrypted or even the whole archive (including filenames).
  • I dont have the volumes on my disk, but I have a Stream subclass which allows random access and provides access to the volumes. This means I use the following constructor:
 var streams = new List<LazyStream>();
 ....
 RarArchive a = RarArchive.Open(streams, Options.None);
  • I try to random access the entry stream
a.Entries.First().OpenEntryStream().Read(...)

Even if we leave out the encryption for a second, we have multiple problems:

  • RarArchiveEntry.OpenEntryStream won't work with incomplete/multipart ArchiveEntries
  • MultiVolumeReadOnlyStream allows no random access

My Questions:

  • Is what I'm trying to achieve technologically possible? Or are there any showstoppers?
  • Would it be possible to achieve such a thing by extending sharpcompress, without having to rewrite almost everything?
  • If it's indeed possible, could you imagine supporting me in extending sharpcompress in that direction (e.g. if I have any questions...) ?

Background:
Movies, Tv Shows hosted on one-click-hosters are often delivered in 100mb parts. I already have a piece of software which allows you to automatically unpack parts (and start watching the content) while the missing parts are still loading.
But if you take this idea to the next level and combine a downloader, extractor and a player into one application, you would be able to provide an even greater experience (seeking !). Seeking in a mkv file is not a problem. Seeking in AES Stream is a bit harder (but should still be possible in theory, right?). But seeking in a multipart rar volume.....

Exception extracting APK archives

It has come to my attention that certain Android package archives (APKs) are not extractable by SharpCompress due to the following exception:

Unhandled Exception:
System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
  at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/mscorlib/system/throwhelper.cs:74 
  at System.BitConverter.ToUInt16 (System.Byte[] value, Int32 startIndex) [0x0002c] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/mscorlib/system/bitconverter.cs:293 
  at SharpCompress.Common.Zip.Headers.ZipFileEntry.LoadExtra (System.Byte[] extra) [0x00007] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/ZipFileEntry..cs:71 
  at SharpCompress.Common.Zip.Headers.LocalEntryHeader.Read (System.IO.BinaryReader reader) [0x0008b] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs:39 
  at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00063] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:42 
  at SharpCompress.Common.Zip.SeekableZipHeaderFactory.GetLocalHeader (System.IO.Stream stream, SharpCompress.Common.Zip.Headers.DirectoryEntryHeader directoryEntryHeader) [0x0001d] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:69 
  at SharpCompress.Common.Zip.SeekableZipFilePart.LoadLocalHeader () [0x0000c] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipFilePart.cs:35 
  at SharpCompress.Common.Zip.SeekableZipFilePart.GetCompressedStream () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipFilePart.cs:21 
  at SharpCompress.Archive.Zip.ZipArchiveEntry.OpenEntryStream () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchiveEntry.cs:17 
  at System.IO.Compression.ZipArchiveEntry.Open () [0x0007f] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/ZipArchiveEntry.cs:115 
  at System.IO.Compression.ZipFileExtensions.ExtractToFile (System.IO.Compression.ZipArchiveEntry source, System.String destinationFileName, Boolean overwrite) [0x00039] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFileExtensions.cs:115 
  at System.IO.Compression.ZipFileExtensions.ExtractToDirectory (System.IO.Compression.ZipArchive source, System.String destinationDirectoryName) [0x00095] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFileExtensions.cs:91 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName, System.Text.Encoding entryNameEncoding) [0x0001a] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFile.cs:131 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFile.cs:117 
  at ExtractTest.MainClass.Main (System.String[] args) [0x00024] in /Users/pjcollins/Desktop/Repro/Program.cs:12 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: Destination array is not long enough to copy all the items in the collection. Check array index and length.
  at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/mscorlib/system/throwhelper.cs:74 
  at System.BitConverter.ToUInt16 (System.Byte[] value, Int32 startIndex) [0x0002c] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/external/referencesource/mscorlib/system/bitconverter.cs:293 
  at SharpCompress.Common.Zip.Headers.ZipFileEntry.LoadExtra (System.Byte[] extra) [0x00007] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/ZipFileEntry..cs:71 
  at SharpCompress.Common.Zip.Headers.LocalEntryHeader.Read (System.IO.BinaryReader reader) [0x0008b] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs:39 
  at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00063] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:42 
  at SharpCompress.Common.Zip.SeekableZipHeaderFactory.GetLocalHeader (System.IO.Stream stream, SharpCompress.Common.Zip.Headers.DirectoryEntryHeader directoryEntryHeader) [0x0001d] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:69 
  at SharpCompress.Common.Zip.SeekableZipFilePart.LoadLocalHeader () [0x0000c] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipFilePart.cs:35 
  at SharpCompress.Common.Zip.SeekableZipFilePart.GetCompressedStream () [0x0000b] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipFilePart.cs:21 
  at SharpCompress.Archive.Zip.ZipArchiveEntry.OpenEntryStream () [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchiveEntry.cs:17 
  at System.IO.Compression.ZipArchiveEntry.Open () [0x0007f] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression/ZipArchiveEntry.cs:115 
  at System.IO.Compression.ZipFileExtensions.ExtractToFile (System.IO.Compression.ZipArchiveEntry source, System.String destinationFileName, Boolean overwrite) [0x00039] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFileExtensions.cs:115 
  at System.IO.Compression.ZipFileExtensions.ExtractToDirectory (System.IO.Compression.ZipArchive source, System.String destinationDirectoryName) [0x00095] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFileExtensions.cs:91 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName, System.Text.Encoding entryNameEncoding) [0x0001a] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFile.cs:131 
  at System.IO.Compression.ZipFile.ExtractToDirectory (System.String sourceArchiveFileName, System.String destinationDirectoryName) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.0/mcs/class/System.IO.Compression.FileSystem/ZipFile.cs:117 
  at ExtractTest.MainClass.Main (System.String[] args) [0x00024] in /Users/pjcollins/Desktop/Repro/Program.cs:12 

From a simple reading of some Zip specs it seems that extra data always should be in a multiple of 2 bytes so I did this simple fix which gets these archives to work:

--- a/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/ZipFileEntry..cs
+++ b/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/ZipFileEntry..cs
@@ -66,6 +66,9 @@ namespace SharpCompress.Common.Zip.Headers

         protected void LoadExtra(byte[] extra)
         {
+            if (extra.Length % 2 != 0)
+                return;
+                       
             for (int i = 0; i < extra.Length;)
             {
                 ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);

Allow Getting of Position of Stream

Retrieval of the position of either the current stream (eg, number of bytes already read) or the underlying compressed stream would be helpful when trying to determine read rates for display.

I am fine with just getting the current position of the underlying stream and not the number of inflated bytes, but I suspect both are equally easy to expose.

ZipReader/StreamingZipReaderFactory fails for archive entries which are uncompressed files in ZIP format

The issue has already been documented on CodePlex (see here). I added my comments and an example ZIP file exhibiting the problem to this issue in CodePlex, trying to keep the information in one place.

A short summary:
If a ZIP archive contains an uncompressed file entry which happens to be file in the ZIP format (such as another ZIP archive, epub, docx, xlsx document, etc...) then trying to extract the ZIP archive using ReaderFactory.Open(...) and IReader.OpenEntryStream(...) will fail.

I am using the SharpCompress version 0.11.1 available on nuget.

Split archive

How can we compress one file and split it to multiple parts?

Windows Phone 8.1 Support

Could you please add WP 8.1 Support to your nuget package. I think the code should be fine for that.

THANKS

Compiler Warning (level 3) CS0675 in DefalteManager.cs

When building SharpCompress project with Warning level above 2 (usually 4 is default) it will fail on lines 683 and 695 of DeflateManager.cs:

unchecked
            {
                if (bi_valid > (int) Buf_size - len)
                {
                    //int val = value;
                    //      bi_buf |= (val << bi_valid);

                    bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS
                    //put_short(bi_buf);
                    pending[pendingCount++] = (byte) bi_buf;
                    pending[pendingCount++] = (byte) (bi_buf >> 8);


                    bi_buf = (short) ((uint) value >> (Buf_size - bi_valid));
                    bi_valid += len - Buf_size;
                }
                else
                {
                    //      bi_buf |= (value) << bi_valid;
                    bi_buf |= (short) ((value << bi_valid) & 0xffff); <-- THIS IS WHERE IT FAILS
                    bi_valid += len;
                }
            }

I believe following line:

bi_buf |= (short) ((value << bi_valid) & 0xffff);

can be replaced using following code instead:

bi_buf = (short)(bi_buf | (short)((value << bi_valid) & 0xffff));

Get NullReferenceException after saving last entry of a 7zip archive

I'm using the example:

var archive = ArchiveFactory.Open(item.FullName);
foreach (var entry in archive.Entries)
{
if (!entry.IsDirectory)
{
entry.WriteToDirectory(@"C:\Research\SharpCompress\SharpCompress\Archives");
}
}

Decompressing is done successfully only if file has some content. If it is empty I get NullReferenceException in ListeningStream.Read (Stream is null). As I understand archiveEntry.OpenEntryStream() returns null.

Archive can be downloaded from the same issue posted on CodePlex.

And it is important, that such issue appears only with 7zip, rar and zip are processed without errors.

UPD. the main reason is that file.HasStream = !emptyStreamVector[i]; is false for my archive. How can it be changed to true?

confused nuget references

I am developing a 'portable' nuget package that references the sharpcompress library however I am having issues when I use my package on .NET40.

My assembly is referencing the sharpcompress.portable assembly but in a .NET40 project the sharpcompress.dll is loaded instead causing a missing reference exception. Manually changing the reference works but is definitely confusing.

Would it be possible to have all your assemblies be called SharpCompress.dll when they are packaged into the nuget package?

Enable "XML documentation file" in the SharpCompress project to enable Intellisense tooltips for users of the SharpCompress library

I noticed in the SharpCompress.csproj project file, that the build setting "XML document file" is not set.
Enabling this setting and set the XML file name to the same as the library (i.e., "SharpCompress.xml") will generate a XML documentation file usable by Intellisense. Put it together with the library in the nuget package, and the users of the SharpCompress library will be able to see Intellisense tooltips with the method/field/class/etc. documentation comments you have already written in the source code...

(I am aware that not all public members of the SharpCompress classes have documentation comments. But many already have. And it would be a shame to not make them available through Intellisense...)

Sample to create a .tar.gz file from source directory

Hello,
I am really in need to find a library which can take of my .tar.gz compression needs.
This library seems promising to me, but somehow I am not able to get around the code to create a sample for .tar.gz file creation from source directory (source directory will contain more sub folder and files).

I would be thankful if the team can add a sample snippet for the same in your documentation or wiki page for reference or in reply to this issue.

-Jsinh

IEntry.Crc and IEntry.Size changes into 0 after WriteTo()

This is the code.

using (var archive = ArchiveFactory.Open("jquery-ui-1.11.4.zip"))
{
    var entry = archive.Entries.Where(v => !v.IsDirectory).First();
    Console.WriteLine(entry.Crc); // not zero
    Console.WriteLine(entry.Size); // not zero

    var mem = new MemoryStream();
    entry.WriteTo(mem);
    Console.WriteLine(entry.Crc); // zero
    Console.WriteLine(entry.Size); // zero
}

In .NET 4.5.2, VS2013, SharpCompress v0.11
zip file: https://jqueryui.com/resources/download/jquery-ui-1.11.4.zip

Also, assembly version of 0.11 is still 0.10.3

Can't write empty directories to ZIP files

Attempting to create an empty directory entry in a ZIP file creates an empty file instead of a directory

A crude fix is as follows - in ZipWriter make the following change:

    public Stream WriteToStream(string entryPath, DateTime? modificationTime, string comment)
    {
        bool isDirectory = entryPath.EndsWith("/");             // PRT
        entryPath = NormalizeFilename(entryPath);
        if (isDirectory)                                        // PRT
            entryPath += "/";                                   // PRT

Cheers,
Paul

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.