See http://sharpcompress.codeplex.com/workitem/24
New Post: File not disposed after use
New Post: FlagUtility.HasFlags not working correctly in Windows 8
I was having problems opening some rar archives in a Windows 8 app because the FilePath was corrupted (had the '\0' and extra chars.
I stepped through the code, and saw that when calling HasFlags to check for Unicode, the enumVal is a negative number, and so enumVal.GetHashCode() is < 0, which is still correct.
The easiest fix, since the code converts the values to UInt32 is to make FileFlags an enum of type ushort, which resolved my problems.
New Post: FileHeader FileName encoding for RAR files
Hi,
I'm trying to extract files from a RAR archive that contains multi-byte characters for the file entries but I cannot seem to get the correct results.
Here's an example of one of those entries: 00 ßalou.jpg
After the header is read, the filename will be set to "00 �alou.jpg\0��", which is incorrect. Upon inspection I have noticed that the Unicode flag is not found causing it to call the DecodeDefault method which boils down to Encoding.UTF8.GetString(). This should be right because the RAR specification states that UTF8 encoding will be used for Multi-byte strings.
I was able to truncate the final part of the string by ignoring the last few bytes after the zero-byte like so:
int length = 0;
while (length < fileNameBytes.Length && fileNameBytes[length] != 0)
{
length++;
}
That does fix the garbage at the end of the string but I have no idea it that is the correct solution. The � in the middle of the string is still present. I've tried to use the FileNameDecoder class (which is supposed to work for unicode strings in RAR files) and that doesn't work (fully)
FileNameDecoder.Decode(fileNameBytes, length) // returns "Ìß"
Notice how it does decode the "ß" character but none of the rest of the string. Does anyone have some more info about this topic? I would love to know how to fix this.
Also I have tried creating an entire new RAR archive with the same entries using WinRar to make sure I am not using a faulty RAR archive.
I'm using dec 11's 0.8.2 - WP7 version in a WinRT application.
New Post: FlagUtility.HasFlags not working correctly in Windows 8
Great find, this solved my problem! Thanks
New Post: Suggestion: implicitly convert CompressionType to CompressionInfo
I'd like to suggest to add the following to CompressionInfo:
public static implicit operator CompressionInfo(CompressionType compressionType) { return new CompressionInfo() { Type = compressionType }; }
This would allow to write e.g.
writableArchive.SaveTo(stream, compressionType);
instead of
writableArchive.SaveTo(stream, new CompressionInfo { Type = compressionType });
while retaining the flexibility introduced with CompressionInfo.
New Post: ArgumentOutOfRangeException during tar file creation
I have a simple CompressFile wrapper method:
privatestring CompressFile(string infile, string outfile) {using (var fs = File.OpenRead(infile))using (var w = File.Open(outfile, FileMode.OpenOrCreate, FileAccess.Write))using (var ws = WriterFactory.Open(w, ArchiveType.Tar, CompressionType.BZip2)) { ws.Write(outfile, fs); }return outfile; }
When I use this method on a tab separated text file that I generate in a different part of the program, I run into a ArgumentOutOfRangeException in SharpCompress.Common.Tar.Headers.TarHeader.Write(Stream output):
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) at System.String.Substring(Int32 startIndex, Int32 length) at SharpCompress.Common.Tar.Headers.TarHeader.Write(Stream output) at SharpCompress.Writer.Tar.TarWriter.Write(String filename, Stream source, Nullable`1 modificationTime, Nullable`1 size) at SharpCompress.Writer.Tar.TarWriter.Write(String filename, Stream source, Nullable`1 modificationTime) at SharpCompress.Writer.IWriterExtensions.Write(IWriter writer, String entryPath, Stream source)
The exported file is being created with the FileHelpers library and is a simple tab separated file with newlines to separate records.
New Post: Suggestion: implicitly convert CompressionType to CompressionInfo
Done!
Thanks.
New Post: FlagUtility.HasFlags not working correctly in Windows 8
Done!
Thanks.
New Post: ArgumentOutOfRangeException during tar file creation
Any chance you're willing to get the source and debug this or give me some more detailed data? I think it has to do with the filename but I'm not 100% sure.
New Post: SharpCompress.Archive.ArchiveFactory.Open() IArchive please implement OpenEntryStream
Hello
ArchiveFactory is good idea, but it gives no full control over extraction. Can you please implement OpenEntryStream here? Like implemented in ReaderFactory
New Post: Optimized reading library
Hi,
I am using it and the last version seems to be a bit slower...I would like to have a special PORTABLE version optimized in size and performance for READ ONLY...do you have any plan like that ?
Other question : is it possible to read twice a stream...to make double loop over the entries ? some like Stream.Position = 0 and redo a while (move to next )...?
Thanks
New Post: accessing a file directly
Hello,
Is there a was to access a file directly (without making a loop on all files in the zip)?
Instead of
var reader = ReaderFactory.Open(stream); while(reader.MoveToNextEntry()) { ... }
making
var reader = ReaderFactory.Open(stream); var file = reader['myfolder/myfile.txt'];
because I have thousand of element in my file, making a look will takes time.
Thanks
New Post: accessing a file directly
You probably ought not to use the Reader for random access. Use the ArchiveFactory for that.
Here's a sample with LINQ (I haven't actually tried this so the code might not be 100%)
var archive = ArchiveFactory.Open(stream);var file = archive.Entries.Where(x => x.Name == "myfolder/myfile.txt").FirstOrDefault();
However, for a reader you'd have to manually loop like this:
var reader = ReaderFactory.Open(stream); while(reader.MoveToNextEntry() && reader.Entry.Name == "") { ... }
New Post: Optimized reading library
You know specially what's slowed down and when? If you use a Reader then it is read only.
For your second question: do you mean with the Archive interface? Everytime you access an EntryStream you should be able to read it again. With the Reader interface, it is forward-only, read-only. You need to make a new one.
New Post: Optimized reading library
Hi,
Thanks to reply. I am only using the reader.
between this two forks, but I do not identify if it is especially the library....it is more a feeling at this time, I will investigate and keep you informed
sharpcompress-996053331ddb
and sharpcompress-f4817f9ce4ac
I have made a special version just for zip/rar - and removed everything not "reader". I will check the archive to see if better for me
Thanks
New Post: accessing a file directly
Thanks this is perfect!
New Post: reading certain entry
Is it possible to get certain entry without,unpacking it on disc?
This is what I have done so far.The problem here is the while loop...Each execution of reader.MoveToNextEntry(); takes ~50ms so if I have a rar with 1k images,it almost takes 1min to get to last image...
public static System.Drawing.Image ReadPageFromRar(string pathToFile, int page)
{
using (Stream stream = File.OpenRead(pathToFile))
{
var reader = ReaderFactory.Open(stream, SharpCompress.Common.Options.KeepStreamsOpen);
int currentPage = 0;
while (currentPage != page)
{
reader.MoveToNextEntry();
currentPage++;
}
using (var entryStream = reader.OpenEntryStream())
{
return Bitmap.FromStream(entryStream);
}
}
}
using (Stream stream = File.OpenRead(@"C:\a.cbr"))
{
var arch = ArchiveFactory.Open(stream, SharpCompress.Common.Options.KeepStreamsOpen);
foreach (var entry in arch.Entries)
{
using (var entryStream = entry.OpenEntryStream())
{
Bitmap.FromStream(entryStream);
}
}
}
This code throws exception The method or operation is not implemented. in SharpCompress.Compressor.Rar.CanSeek
New Post: reading certain entry
To avoid having to decompress the entire RAR, you need to use ArchiveFactory (like in your 2nd example) unless it's a SOLID archive.
The second example probably fails because EntryStreams aren't Seekable. However, it looks like a bug because CanSeek should work.
Can you give me a complete stacktrace to verify this? Thanks.
New Post: Office compatible archives
I'm working on a Windows Phone 8 app and am not having any luck creating a zip (renamed to .ppsx) that PowerPoint will open. I'm using ~98% the same code that works with my Windows 8 app utilising System.IO.Compression to create a zip. Since that library is not available in WP8 I gave SharpCompress a go. Is there a trick or certain compression format that I need to use to create a valid Office Open XML document? If I extract and re-zip my SharpCompress created archive using Windows File Explorer, PowerPoint opens the file no problems.
New Post: Office compatible archives
I haven't looked into what Zip style/file format that MS Office would expect.