Came across this when I ran into a rar file that threw the InvalidFormatException "Invalid Rar Header" (RarHeaderFactory.cs line 195).
If it runs into this error, then I want to move the file to another directory (using FileInfo.MoveTo).
Here's the thing:
If the archive is opened via a file path:
However, if you open the archive by a single file stream surrounded by a using:
I am assuming this behavior is because the stream is being closed/disposed in the 'single file stream' example.
The problem with using 'single file streams' is that it appears that 'IsComplete' doesn't parse properly (at least in the tests I have done). IsComplete works fine when you pass a file path or an IEnumerable set of streams, but not a single file stream.
Not sure of the exact logic of IsComplete, but I am guessing that it either uses the file path to find the other files or uses the set of streams to determine if the required volumes are present, so passing a single file stream wouldn't have the information to check IsComplete?
Is there anyway that the stream can be closed when the exception is thrown (if opened by a file path or set of streams), or can IsComplete be modified to work with a single file stream?
cheers
If it runs into this error, then I want to move the file to another directory (using FileInfo.MoveTo).
Here's the thing:
If the archive is opened via a file path:
var archive = RarArchive.Open(fi.FullName);
or via an IEnumerable set of streams:var archive = RarArchive.Open(files.Select(f => File.OpenRead(f.FullName));
after it throws the InvalidFormatException, if you try to move the file it comes back with "The process cannot access the file because it is being used by another process.". However, if you open the archive by a single file stream surrounded by a using:
using (var stream = File.OpenRead(f.FullName))
{
using (var archive = RarArchive.Open(stream))
{
...
}
}
then it's possible to move the file.I am assuming this behavior is because the stream is being closed/disposed in the 'single file stream' example.
The problem with using 'single file streams' is that it appears that 'IsComplete' doesn't parse properly (at least in the tests I have done). IsComplete works fine when you pass a file path or an IEnumerable set of streams, but not a single file stream.
Not sure of the exact logic of IsComplete, but I am guessing that it either uses the file path to find the other files or uses the set of streams to determine if the required volumes are present, so passing a single file stream wouldn't have the information to check IsComplete?
Is there anyway that the stream can be closed when the exception is thrown (if opened by a file path or set of streams), or can IsComplete be modified to work with a single file stream?
cheers