-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
I'm downloading a file from an FTP server and unzipping, untarring it on the fly, via the underlying streams. The code looks like this:
var request = WebRequest.Create("ftp://host/file.tgz");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("user","password");
var response = (FtpWebResponse) await request.GetResponseAsync();
using (var gzStr = new GZipInputStream(response.GetResponseStream()))
{
gzStr.IsStreamOwner = false;
var tar = TarArchive.CreateInputTarArchive(gzStr);
Directory.CreateDirectory(_targetPath);
tar.IsStreamOwner = false;
tar.ExtractContents(_targetPath);
}With the current 1.2.0 release (and 1.1.0 and 1.0.0) I get an ObjectDisposedException on the network socket stream, but it happens after the whole file has been extracted successfully, so it seems to be yet another exceptional case happening after finishing the file.
In my total ignorance of this code, I've tracked the issue to this line:
| catch (Exception ex) when (completedLastBlock && (ex is GZipException || ex is EndOfStreamException)) |
catch (Exception ex) when (completedLastBlock &&
(ex is GZipException || ex is EndOfStreamException)) and, changing it to
catch (Exception ex) when (completedLastBlock &&
(ex is GZipException || ex is EndOfStreamException ||
ex is ObjectDisposedException))makes my specific case work successfully. I think that the server ends the connection after the file is downloaded so the stream is not there to be read from anymore.