Quantcast
Channel: sharpcompress Discussions Rss Feed
Viewing all 239 articles
Browse latest View live

New Post: 7z extraction problem

$
0
0
Sorry, I haven't had time to look at why this is happening. My guess is an implement 7zip header implementation that I did. I have a new one in a branch but no time to fully test.

In short, LZMA2 ought to be supported.

New Post: Compiling from source

$
0
0
Ok thanks, how do I use/compile the unit test? Is this for the DLL version?

New Post: Compiling from source

$
0
0
err.. anyone would like to share a simple working example? :-)

New Post: Compiling from source

New Post: Compiling from source

$
0
0
Thanks Adam,

I'm currently using VC2010 express so I don't think I have the MSTest tool. Maybe a full .cs file and references? I'm trying to build it to an executable..

BTW, do I need to use [DLLImport ...]?

New Post: Compiling from source

$
0
0
sharpcompress is C#/.NET DllImport is for native code.

You should just reference the sharpcompress DLL like any other C# DLL, add some using statements then try some of the sample code. You seem very new to C# so you need to get some basics down first.

New Post: Compiling from source

$
0
0
Wow, finally got one sample working using this using heading:

using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.Reader;

Thanks again!

New Post: Sample for LzmaStream

$
0
0
Hi,

I try to create LzmaStream compressor by using this:
            ms.WriteByte(9);
            ms.WriteByte(20);
            ms.WriteByte(5);
            ms.WriteByte(0);

            LzmaStream lzmaStream = new LzmaStream(new LzmaEncoderProperties(!ms.CanSeek, 10000), false, ms);
            ms.Write(lzmaStream.Properties, 0, lzmaStream.Properties.Length);
            return lzmaStream;
and decompressor by this:
            var reader = new BinaryReader(ms);
            reader.ReadUInt16(); //LZMA version
            var props = new byte[reader.ReadUInt16()];
            reader.Read(props, 0, props.Length);
            return new LzmaStream(props, ms, ms.Length - 4 - props.Length, -1); 
both ms is MemoryStream for the input source.

During decompress, I get DataErrorException in
SharpCompress.Compressor.LZMA.Decoder

Do you have sample for LzmaStream?

Thanks.

New Post: Sample for LzmaStream

$
0
0
Sorry, the only sample is what's in the code. I'm not an expert on LzmaStream as it was a contribution. Please dig into the code as see if you can find more about it's usage.

New Post: InvalidFormatException not releasing file

$
0
0
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:
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

New Post: InvalidFormatException not releasing file

$
0
0
I think the problem is with IsComplete. I think you're assessment of the disposing is correct. You have to manage your own streams if you give them to SharpCompress as well as use using blocks liberally.

IsComplete doesn't force the parsing of the archive fully like other operations. This seems like a bug and I think I've now fixed it:
https://sharpcompress.codeplex.com/SourceControl/changeset/2f8ce7087d9b

New Post: Extracting from non solid archive

$
0
0
hi all,

can someone please show me how i extract files from a non solid rar archive?

I've tested the file using IsSolid, and its returning false, but i then can't figure out how to extract entries from the archive to a directory.

I've managed to use RarArchive to extract from solid archives OK, but i keep getting errors when extracting the files from a non solid archive using a reader.

thanks

New Post: Extracting from non solid archive

$
0
0
What code are you using to try to extract from the archive?

New Post: Extracting from non solid archive

$
0
0
This is the code i'm using for writing the file for solid archives. it is giving me the error for non solid archives when it reaches the last file. Plus I don't think that it is extracting the files correctly anyway when using a non-solid archive.

I want to do the same thing for non solid archives if possible.
For Each entry In Archive.Entries
                ' make sure sample does not appear in the file name
                If InStr(entry.FilePath, "sample") = 0 And entry.IsComplete Then
                    Try
                        If Not File.Exists(strOutputDir & "\" & entry.FilePath) Then
                            entry.WriteToDirectory(strOutputDir, SharpCompress.Common.ExtractOptions.None)
                            WriteToLog("Extracting " & entry.FilePath & " completed.")
                        Else
                            WriteToLog(strOutputDir & "\" & entry.FilePath & " already exists - skipping.")
                        End If

                        ErrorNumber = ReturnCodes.OK

                    Catch ex As Exception
                        WriteToLog("Error extracting files - " & ex.Message)
                        ErrorNumber = ReturnCodes.ErrorExtractingRar
                        Exit For
                    End Try

                Else
                    WriteToLog(ReturnMessages(ReturnCodes.SampleFileSkipped))
                End If

            Next
all I have at the moment is
 If Not Archive.IsSolidArchive Then
            Dim _stream = File.OpenRead(FileName)
            Dim _reader = SharpCompress.Reader.ReaderFactory.Open(_stream)
            While _reader.MoveToNextEntry()
                If Not _reader.Entry.IsDirectory Then
                    'write the file
                End If
            End While
    
        End If

New Post: Extracting from non solid archive

$
0
0
Sorry, VB.NET is hard for me to read :/

What is the exception that is thrown?

New Post: Extracting from non solid archive

$
0
0
The exception is
{"Object reference not set to an instance of an object."}
and it only seems to occur when at the end of the archive i.e. the last file

i'm thinking that this extraction should just be 10 lines of code or something. If you can write something in c# that loops the files in an archive and extracts them to a directory, i'll attempt to upgrade it to vb.net :)

thanks

New Post: Extracting from non solid archive

New Post: Can you read entries concurrently?

$
0
0
Hi,
I was trying to read entries concurrently and then save the output as a file, however the output image is corrupted.

private async Task<string> SaveFileAsyncReadingSync(Stream streamSource, StorageFolder destinationStorageFolder, string destinationFileName)
    {
        var file = await destinationStorageFolder.CreateFileAsync(destinationFileName, CreationCollisionOption.ReplaceExisting);

        using (var ostream = await file.OpenStreamForWriteAsync())
        {
            int count = 0;
            do
            {
                var buffer = new byte[1024];
                count = streamSource.Read(buffer, 0, 1024);
                await ostream.WriteAsync(buffer, 0, count);
            }
            while (count > 0);
        }

        return destinationStorageFolder.Name + "/" + file.Name;
    }
this is the code I use to read/write. Am I doing something wrong?

Thanks

New Post: WP8 NotSupportedException during ArchiveFactory.Open

$
0
0
I love this library. So simple to use. I'm using it to decompress images from a cbr file (rar file for comic book images).

It works fine! But I do get a NotSupportedException in debug everytime I run this code:
using (IArchive archive = ArchiveFactory.Open(raStream.AsStream()))
                {
                    var entry = archive.Entries.ElementAt(pageNumber);
                    MemoryStream stream = new MemoryStream();
                    entry.WriteTo(stream);
                    bitmapImage.SetSource(stream);
                }
It shows up during the using statement. Mostly I just wanted to say thanks for writing this. But if there's a good reason I'm getting this exception, I wouldn't mind knowing why... :)

New Post: WP8 NotSupportedException during ArchiveFactory.Open

$
0
0
There are some features that aren't in the portable version.

Can you show me a complete stacktrace?
Viewing all 239 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>