adamhathcock / sharpcompress Goto Github PK
View Code? Open in Web Editor NEWSharpCompress is a fully managed C# library to deal with many compression types and formats.
License: MIT License
SharpCompress is a fully managed C# library to deal with many compression types and formats.
License: MIT License
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.
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:
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);
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 ArchiveEntriesMultiVolumeReadOnlyStream
allows no random accessMy 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.....
When opening a RAR File with ReaderFactory.Open, it defaults to returning a SingleVolumeReader which fails when the RAR file is a MultiVolumeRar.
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.
How can we set password when creating archives?
When processing a password protected ZIP file using the high level IArchiveReader/Writer interfaces, it is not possible to supply the password as this functionality is only exposed by lower level interfaces.
Cheers,
Paul
If the TAR compressed "2G or more files" will be completed abnormally.
File list
In the TAR compressed content "c file" is not included.
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); //??
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!
i wite a file with a head pack and then wite the zip file after,but when i read this file to seek the zip date start position,then throw error!!!
Are you going to do something for the extraction of an archive that is protected with a password?
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));
Hi, it's possible to create zip archive with a password
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.
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
Could you please add WP 8.1 Support to your nuget package. I think the code should be fine for that.
THANKS
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.
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
The following zip file throws an unknown header exception
http://downloadmirror.intel.com/24498/a08/gfx_7-8.1_15.36.0.4014_beta.zip
Cheers,
Paul
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);
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?
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
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
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.
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;
}
}
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.
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.
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?
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?
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
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
How can we compress one file and split it to multiple parts?
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!
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.
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.
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.
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...)
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")]
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?
If you list a ZIP file contents with SharpCompress and display the created and modified dates, they are sometimes off by one or two hours when compared with Windows File Explorer
Cheers,
Paul
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.
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
.
Hi, it's possible to compress to rar file using a password with sharpcompress???????
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?
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.
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?
When you run tests first time, some tests fail. Then if you rerun unpassed tests, they will pass. Seems like a bug in concurrency
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?
I was using the ZipArchive with Writing example here: https://github.com/adamhathcock/sharpcompress/wiki/API-Examples. I have the nuget package SharpCompress.0.11.0.
The code fails to compile, saying AddAllFromDirectoryEntry is not defined. Is this an extension method in some other namespace/DLL? I do not know where to find it.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.