adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.24k stars 480 forks source link

I get a Value cannot be null error on some gzips but not others #443

Open rickyelqasem opened 5 years ago

rickyelqasem commented 5 years ago

I get error: System.ArgumentNullException: 'Value cannot be null. Parameter name: path2' on some gzips but not others that are in the same directory when I try to extract them

string endTarget = @"d:\TestUEF"; string[] files2 = Directory.GetFiles(sourcePath); foreach (string file in files2) { string filePath = @file; using (Stream stream = File.OpenRead(filePath)) { var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(endTarget, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } }

adamhathcock commented 5 years ago

Stacktrace and version is needed

rickyelqasem commented 5 years ago

Not working zip > https://bit.ly/2TPl9lm Working zip > https://bit.ly/2TNCR8W .net = 4.6.1 sharpcompress = Install-Package sharpcompress -Version 0.23.0

System.ArgumentNullException HResult=0x80004003 Message=Value cannot be null. Parameter name: path2 Source=mscorlib StackTrace: at System.IO.Path.Combine(String path1, String path2) at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write) at SharpCompress.Readers.IReaderExtensions.WriteEntryToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options) at UEF_Extractor.Form1.extractUEFFilesToolStripMenuItem_Click(Object sender, EventArgs e) in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Form1.cs:line 84 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.MenuStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at UEF_Extractor.Program.Main() in D:\OneDrive\devwork\UEF Extractor\UEF Extractor\Program.cs:line 19

rickyelqasem commented 5 years ago

Its got something to do with the contents which is a file without the filename attribute so when I extract with winrar it gives the file the same name as the zip with the .zip extension.

adamhathcock commented 5 years ago

Since that's the case, you should can handle it yourself.

The WriteEntryToDirectory type methods are extensions to make common scenarios easy but it doesn't handle everything. My intent isn't to have a fully fledged WinZip/WinRAR UI facing library but a more raw one that allows developers to do what they need to more easily. I've tried to avoid doing a lot of file-facing things.

rickyelqasem commented 5 years ago

I actually found an alternate going back to system.io.compress > https://stackoverflow.com/questions/24138373/unzip-gz-file-using-c-sharp < this is working for me now.

Bond-009 commented 2 years ago

no-filename.gz A test file for whoever wants to fix this and a test

Rombersoft commented 2 weeks ago

I see this bug is not fixed yet. Version 0.37.2

adamhathcock commented 2 weeks ago

You can fix it yourself and please add a test. My comment still stands about the convenience method and the ability to handle all entries the way you want to.