mickle026 650 Posted November 11, 2024 Posted November 11, 2024 (edited) I am trying to unzip a file that I have downloaded inside a plugin, but all I keep getting is an exception. If I dont get an exception , nothing is unzipped either. ZipFile is the Path to the zip including the filename. extractPath is the directory folder to extract it to. The header magic is 1F 8B (a gzip) private readonly IZipClient gzipClient; using (FileStream fs = File.Open(ZipFile, FileMode.Open)) { //gzipClient.ExtractAllFromZip(fs, extractPath, true); gzipClient.ExtractAllFromGz(fs, ExtractedZip, true); } I thought it would be easy, but I am not getting any extracted files. Is there something I need to do other than the above? Edited November 11, 2024 by mickle026
mickle026 650 Posted November 11, 2024 Author Posted November 11, 2024 this is the error Quote 11.Nov.2024 - 17:44:54 IMDBDataSetLocalFileSize: 7.18 MB 11.Nov.2024 - 17:44:54 IMDBDataSetRemoteFileSize: 7.18 MB 11.Nov.2024 - 17.45.02 GZ Unzip:- ZipFile:D:\cache\MechBox\ImdbDatasets\Zips\title.ratings.tsv.gz Extract To:D:\cache\MechBox\ImdbDatasets 11.Nov.2024 - 17.45.02 Exception Occured: D:\cache\MechBox\ImdbDatasets\Zips\title.ratings.tsv.gz System.ArgumentNullException: Value cannot be null. (Parameter 'path2') at System.ArgumentNullException.Throw(String paramName) 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.WriteAllToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options) at Emby.Server.Implementations.Archiving.ZipClient.ExtractAllFromGz(Stream source, String targetPath, Boolean overwriteExistingFiles) at MechBox.MechBox.Get(IMDBDataSetDownload result) it says path2 is null try { using (FileStream fs = File.Open(ZipFile, FileMode.Open)) { log.LogToMyFile(currentlog, DateTime.Now.ToString("dd.MMM.yyy - HH'.'mm'.'ss") + $" GZ Unzip:-\nZipFile:{ZipFile} \nExtract To:{extractPath}"); gzipClient.ExtractAllFromGz(fs, extractPath, true); } } catch (Exception e) { log.LogToMyFile(currentlog, DateTime.Now.ToString("dd.MMM.yyy - HH'.'mm'.'ss") + $" Exception Occured:\n{ZipFile}\n {e.ToString()}"); } It seems to be telling me there is a Path.Combine in here ???
mickle026 650 Posted November 11, 2024 Author Posted November 11, 2024 (edited) The zip is downloaded with web client like any other file. It works fine , I can unzip it with WinZip/winrar and I am waiting for it's lock to be released before trying to unzip it. It sounds by your response that I am doing it correctly, and you are looking for other issues... The download is fine, the paths are fine. I am not getting any other errors Value cannot be null. (Parameter 'path2') at System.ArgumentNullException.Throw(String paramName) at System.IO.Path.Combine(String path1, String path2) The error is confusing, what path combine? They only time I use it is to create the zip file path and the output folder. I log them here: ZipFile:D:\cache\MechBox\ImdbDatasets\Zips\title.ratings.tsv.gz Extract To:D:\cache\MechBox\ImdbDatasets They are valid paths. Edited November 11, 2024 by mickle026
Solution mickle026 650 Posted November 12, 2024 Author Solution Posted November 12, 2024 (edited) 3 hours ago, Luke said: What did you pass in for extractedzip? The directory path to extract to. The path exists. D:\cache\MechBox\ImdbDatasets I think it is something to do with the gz file on imdb's server itself. If I change the .gz archive name and open it, then the filename inside the archive also changes to the same. I am therefore assuming the file itself is gz encrypted rather than "containing" a gzip encrypted file - does that make sense? so I tested with ExtractFirstFileFromGz and it works properly. It seems I was missunderstanding that the gz format and that it is not a "container" if it only has 1 file, but itself gz encoded. { [Route("/MechBox/ExtractGzip", "Get", IsHidden = true, Summary = "TestingExtractZip")] [Authenticated(Roles = "Admin")] public class ExtractGzip : IReturn<object> { public string Text { get; set; } } public async Task<string> Get(ExtractGzip request) { Stream fs = GetFileStream(@"D:\cache\MechBox\ImdbDatasets\Zips\title.gz"); gzipClient.ExtractFirstFileFromGz(fs, @"D:\cache\MechBox\ImdbDatasets","test.tsv"); return JsonSerializer.SerializeToString(new ExtractGzip() { Text = "Test Done!" }); } public static Stream GetFileStream(string fileName) => File.OpenRead(fileName); Edited November 12, 2024 by mickle026
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now