I don't see any sharpcompress API usage in this. I don't think I understand what you're asking me.
↧
New Post: Can you read entries concurrently?
↧
New Post: Can you read entries concurrently?
Sorry, the code got cut
SaveFileAsyncReadingSync(entry.OpenEntryStream(), folders[id], entry.FilePath)
where entry is each one of the RarArchiveEntry in my RARfile. The calls are concurrent, and the resulting images are corrupted. However if I do the calls sequentially everything works fine.
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;
}
}
and it's called by:SaveFileAsyncReadingSync(entry.OpenEntryStream(), folders[id], entry.FilePath)
where entry is each one of the RarArchiveEntry in my RARfile. The calls are concurrent, and the resulting images are corrupted. However if I do the calls sequentially everything works fine.
↧
↧
New Post: Working examples of library
Hi All,
Today I came across this library and I would like to congratulate the developers for great work. I have couple of queries -
Is this library supports .war, .ear file extensions?
and where I can find some good examples of reading different file formats and zipping different file formats, with extracting it and without extracting it?
Is there any option to just check if a file is present in zip file or not? I think it would be possible with this library or we can use LINQ?
I am able to extract zip and rar file.
Thanks
Today I came across this library and I would like to congratulate the developers for great work. I have couple of queries -
Is this library supports .war, .ear file extensions?
and where I can find some good examples of reading different file formats and zipping different file formats, with extracting it and without extracting it?
Is there any option to just check if a file is present in zip file or not? I think it would be possible with this library or we can use LINQ?
I am able to extract zip and rar file.
Thanks
↧
New Post: Working examples of library
The library figures out the archive type by inspecting the binary. wars and ears are zip file if I remember correctly.
There are a lot of examples in the tests. Look at the source.
The Entries collection on the Archive objects have all the entries. Inspect that with LINQ.
There are a lot of examples in the tests. Look at the source.
The Entries collection on the Archive objects have all the entries. Inspect that with LINQ.
↧
New Post: Can you read entries concurrently?
I see. Yes, you can't concurrently use the same instance as it's backed by a single Stream that it seeks over.
You're better off creating multiple Archive instances and having a read only FileStream for each instance. I believe you can have multiple read only FileStreams over the same file.
You're better off creating multiple Archive instances and having a read only FileStream for each instance. I believe you can have multiple read only FileStreams over the same file.
↧
↧
New Post: Working examples of library
Thanks for the reply.
↧
New Post: Great library!
Just want to say thanks, i'm using SharpCompress to extract zip/rar/cbr/cbz files in my open source image viewer (http://www.pviewer.net), i also wrote a small article on how to show a progress bar when extracting files here: http://outofrangeexception.blogspot.com/2013/03/how-to-extract-zip-or-rar-file-in-c.html
Thanks again for your great work!
Thanks again for your great work!
↧
New Post: Great library!
Thanks for the article. I hope people find it useful.
I might use your project as well :)
I might use your project as well :)
↧
New Post: How to ignore directories and the usage of SharpCompress.Common.Options.GiveDirectoryEntries
Hello,
I'm trying to skip the processing of directory entries contained in archives (but I still want to process the regular files contained within).
First, I've tried to use the IsDirectory property of the RarArchiveEntry class, but it always returns false, so it's not use.
I've seen there is a SharpCompress.Common.Options.GiveDirectoryEntries option, which might be related to my problem, but using it doesn't result in any visible change to the archive retuned by RarArchive.Open(stream, options).
Any help? Whats the intended usage of SharpCompress.Common.Options.GiveDirectoryEntries?
I'm trying to skip the processing of directory entries contained in archives (but I still want to process the regular files contained within).
First, I've tried to use the IsDirectory property of the RarArchiveEntry class, but it always returns false, so it's not use.
I've seen there is a SharpCompress.Common.Options.GiveDirectoryEntries option, which might be related to my problem, but using it doesn't result in any visible change to the archive retuned by RarArchive.Open(stream, options).
Any help? Whats the intended usage of SharpCompress.Common.Options.GiveDirectoryEntries?
↧
↧
New Post: How to ignore directories and the usage of SharpCompress.Common.Options.GiveDirectoryEntries
I probably ought to remove that option as Rar is the only thing that pays attention to it.
Right now you have to specify the "GiveDirectoryEntries" option for it to return directories. However, I'm going to remove this unless you protest.
Right now you have to specify the "GiveDirectoryEntries" option for it to return directories. However, I'm going to remove this unless you protest.
↧
New Post: How to ignore directories and the usage of SharpCompress.Common.Options.GiveDirectoryEntries
My confusion stemmed from the fact that it returns directories whether you specify GiveDirectoryEntries or not. Also, the IsDirectory property always returns false.
I have no problem with you removing these since it doesn't work anyway, it would be cool to have IsDirectory working, though.
I have no problem with you removing these since it doesn't work anyway, it would be cool to have IsDirectory working, though.
↧
New Post: Issue
I wrote a sample follow the documentation.
public static void Compress(string[] filesList, string descZipFolder,bool IsDelOrginalFile)
what shall I do? Is is the reason that I didn't close the stream?
public static void Compress(string[] filesList, string descZipFolder,bool IsDelOrginalFile)
{
CompressionInfo info = new CompressionInfo();
info.Type = CompressionType.Deflate;
info.DeflateCompressionLevel = global::SharpCompress.Compressor.Deflate.CompressionLevel.Level6;
using (var zip = File.OpenWrite(Path.Combine(descZipFolder, GenerateZipFileName())))
{
using (var zipWriter = WriterFactory.Open(zip, ArchiveType.Zip, info))
{
foreach (var filePath in filesList)
{
zipWriter.Write(Path.GetFileName(filePath), filePath);
}
}
}
if (IsDelOrginalFile)
{
filesList.ToList().ForEach(item => File.Delete(item));
}
}
but i didn't delete the orginal file, it shown me the message "It is used by another process, you can't access it."what shall I do? Is is the reason that I didn't close the stream?
↧
New Post: Great library!
How to delete the orginal files(they are compressed into the *.zip file) after compressed?
↧
↧
New Post: Great library!
A simple foreach loop will work, try this code with some bogus files first, since i haven't tested it.
string files = Directory.GetFiles(directory).Where(name => !name.EndsWith(".zip"));
foreach (string f in files)
{
File.Delete(f);
}
string files = Directory.GetFiles(directory).Where(name => !name.EndsWith(".zip"));
foreach (string f in files)
{
File.Delete(f);
}
↧
New Post: Issue
I just did a test and things work for me.
Do you have the latest source compiled? Or are you using the last release?
Are you sure you're not opening the files in filesList anywhere else?
Do you have the latest source compiled? Or are you using the last release?
Are you sure you're not opening the files in filesList anywhere else?
↧
New Post: Missing File in UnitTests?
I couldn't get the unit tests to run until I copied тест.txt into the TestArchives\Original Folder. (I got this from running one of the ZipReaderTests)
After that all the tests passed.
Cheers
Simon
After that all the tests passed.
Cheers
Simon
↧
New Post: Missing File in UnitTests?
Unfortunately, there is. That file has a Russian name for testing and it seems TortoiseHg won't add it to the repo correctly.
The only thing I know to do is tell you to do what you did :)
The only thing I know to do is tell you to do what you did :)
↧
↧
New Post: ZipX files
Hi again
I am currently using DotNetZip to read .ZIP files to scan for MS Office Documents then parse Custom Properties directly from them.
There is a limitation that DotNetZip doesn't support LZMA compression which I have in my .ZIPX files (created with WinZip Pro). It can open .ZIPX files but just won't read LZMA coded entries.
I was under the impression that .ZIP files only deflated and only .ZIPX files supported LZMA (and BZIP2 and PPMd) but from your unit tests, It seems to me that ZIP/.ZIPX is just the name of the wrapper and both just contain ZipEntries with various compression types.
So I am interested in your library to support more compression types than DotNetZip and also the streaming support since I need to traverse .ZIP files to any level and the whole thing slows down when I have to extract large, nested .ZIP file before I can read them.
So my questions are:
1) Am I correct that your library can support any .ZIPX file (except for entries compressed as 96 - jpeg compression)?
2) Will the streaming support allow me to recursively scan nested .ZIP(x) files without having to decompress them to temporary files first?
3) When I find an MS Office Document, for the smaller documents at least, I would like to be able to parse them 'in memory' - can I decompress directly to a memory stream?
Finally, a quick question about the licence:
As I understand it, I can use your code in my closed-source, potentially commercial app without any problems. Which is great for me but what about you? Have you set up a donation-ware thing yet?
I am currently using DotNetZip to read .ZIP files to scan for MS Office Documents then parse Custom Properties directly from them.
There is a limitation that DotNetZip doesn't support LZMA compression which I have in my .ZIPX files (created with WinZip Pro). It can open .ZIPX files but just won't read LZMA coded entries.
I was under the impression that .ZIP files only deflated and only .ZIPX files supported LZMA (and BZIP2 and PPMd) but from your unit tests, It seems to me that ZIP/.ZIPX is just the name of the wrapper and both just contain ZipEntries with various compression types.
So I am interested in your library to support more compression types than DotNetZip and also the streaming support since I need to traverse .ZIP files to any level and the whole thing slows down when I have to extract large, nested .ZIP file before I can read them.
So my questions are:
1) Am I correct that your library can support any .ZIPX file (except for entries compressed as 96 - jpeg compression)?
2) Will the streaming support allow me to recursively scan nested .ZIP(x) files without having to decompress them to temporary files first?
3) When I find an MS Office Document, for the smaller documents at least, I would like to be able to parse them 'in memory' - can I decompress directly to a memory stream?
Finally, a quick question about the licence:
As I understand it, I can use your code in my closed-source, potentially commercial app without any problems. Which is great for me but what about you? Have you set up a donation-ware thing yet?
↧
New Post: ZipX files
I don't necessarily know what ZIPX is. The ZIP specification lists LZMA, PPMd, bzip2, etc as compression types so that's what I use as I have those compression types.
As far as I know, there are two archive formats: ZIP and ZIP64. Unfortunately, I haven't implemented ZIP64 yet but it seems straight forward.
1) If ZIPX is just ZIP then it anything ought to work. I don't handle JPEG compression internally but I guess it could do it.
2) Yes. The idea with streaming is that everything is done on the fly in a forward-only stream of bytes. You ought to be able to chain the output of a a current entry on a ZipReader to another ZipReader and have it work.
3) Yes, you can decompress to any stream. Just use the EntryStream and use CopyTo on your MemoryStream and nothing will have to get written to disk.
License is MS-PL which means you can use it anyway you like. What I'd really like is some code/fixes/features given back to the project and some links/usage notes in apps. I guess I ought to setup some donation thing though that obligates me to work when I've already got a full time job :)
As far as I know, there are two archive formats: ZIP and ZIP64. Unfortunately, I haven't implemented ZIP64 yet but it seems straight forward.
1) If ZIPX is just ZIP then it anything ought to work. I don't handle JPEG compression internally but I guess it could do it.
2) Yes. The idea with streaming is that everything is done on the fly in a forward-only stream of bytes. You ought to be able to chain the output of a a current entry on a ZipReader to another ZipReader and have it work.
3) Yes, you can decompress to any stream. Just use the EntryStream and use CopyTo on your MemoryStream and nothing will have to get written to disk.
License is MS-PL which means you can use it anyway you like. What I'd really like is some code/fixes/features given back to the project and some links/usage notes in apps. I guess I ought to setup some donation thing though that obligates me to work when I've already got a full time job :)
↧
New Post: Problem with Unknown Header (and possible fix)
I thought I'd give the library a real workout - a 1.8GB .ZIPX file which is > 3GB when uncompressed and contains 100+ nested .ZIP files.
I had a problem with a single 'unknown' header. By adding a Try Catch, I could scan recursively the whole .ZIPX file and get nearly the same counts as with the DotNetZip code I am already using. (The difference being 3 files from a nested .ZIP entry)
Here is the Unit Test so you can see what I am doing:
This isn't recognized by SharpCompress and so throws the Unknown Header exception.
However I found that if I just ignore this header (by adding a switch case for that signature and creating a null header), then all the rest of the entries are correctly read and I now get exactly the same results as DotNetZip - ie I can now see those 3 missing files
I had a look around in the code and on the internet and found the following:-
There is some ambiguity over that signature:
This page http://www.sxlist.com/TECHREF/language/delphi/swag/ARCHIVES0022.html written by Phil Katz says 0x06064650 is END OF CENTRAL DIR STRUCTURE (and I found this on a couple of other pages)
However, this page http://fileanalysis.net/zip/ says it is "zip64 end of central directory record"
This contradicts the constant in your code which says that
Now, the latter webpage says that signature is actually "zip64 end of central directory locator" and their example shows it directly in front of the 0x06064b50 entry.
So here is my interpretation:-
1) My sample ZIPX file has the 0x0606 header but not the 0x0706 header. This was creating using WinZip Pro BTW. Therefore I am guessing that the Locator 0x0706 is either optional or can be omitted when the next header is a zip64 End of CentralDirectory record.
2) I think your naming of 0x0706 is incorrect - it should be Zip64EndOfCentralDirectory__Locator__Signature not Record. This is confirmed by checking the DotNetZip source code.
3) The Zip64xxx headers can be ignored until zip64 support is added.
4) It is preferred to do this rather than throw an unknown header exception because otherwise the entire containing zip may be unreadable. In the sample code above, you can see I'm using Linq to order the Entries by their FilePath. Until I skipped these zip64 headers, I could not use this code because the exception stopped access to all of the entries.
The only changes I needed were these - case statements (including deleting the existing case ZIP64_END_OF_CENTRAL_DIRECTORY:) and an IgnoreHeader class:-
I had a problem with a single 'unknown' header. By adding a Try Catch, I could scan recursively the whole .ZIPX file and get nearly the same counts as with the DotNetZip code I am already using. (The difference being 3 files from a nested .ZIP entry)
Here is the Unit Test so you can see what I am doing:
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Framework.Streams;
using NUnit.Framework;
using SharpCompress.Archive;
namespace Framework.UnitTest
{
[TestFixture]
public class SharpCompressTests
{
[Test, Ignore]
public void ParseBigZipFile()
{
const string Filename = @"F:\B.Zip";
ProcessZipFile(Filename);
Debug.WriteLine("FileCount={0:n0}", FileCount);
Debug.WriteLine("DirectoryCount={0:n0}", DirectoryCount);
Debug.WriteLine("ZipFileCount={0:n0}", ZipFileCount);
}
static int FileCount;
static int DirectoryCount;
static int ZipFileCount;
static Stream ExtractToStream(IArchiveEntry entry)
{
var result = TemporaryStream.Create(entry.Size);
entry.WriteTo(result);
result.Position = 0;
return result;
}
static void ProcessZipFile(string zipFilename, Stream zipStream = null)
{
using (var archive = zipStream == null ? ArchiveFactory.Open(zipFilename) : ArchiveFactory.Open(zipStream))
{
foreach (var entry in archive.Entries.OrderBy(e => e.FilePath))
{
if (entry.IsDirectory)
{
DirectoryCount++;
continue;
}
var extension = Path.GetExtension(entry.FilePath);
if (string.Compare(extension, ".zip", StringComparison.OrdinalIgnoreCase) == 0)
{
ZipFileCount++;
using (var zipEntryStream = ExtractToStream(entry))
{
ProcessZipFile(Path.Combine(zipFilename, entry.FilePath), zipEntryStream);
}
}
else
{
FileCount++;
}
}
}
}
}
}
The problem is a 0x06064b50 signature in my .ZIPX file.This isn't recognized by SharpCompress and so throws the Unknown Header exception.
However I found that if I just ignore this header (by adding a switch case for that signature and creating a null header), then all the rest of the entries are correctly read and I now get exactly the same results as DotNetZip - ie I can now see those 3 missing files
I had a look around in the code and on the internet and found the following:-
There is some ambiguity over that signature:
This page http://www.sxlist.com/TECHREF/language/delphi/swag/ARCHIVES0022.html written by Phil Katz says 0x06064650 is END OF CENTRAL DIR STRUCTURE (and I found this on a couple of other pages)
However, this page http://fileanalysis.net/zip/ says it is "zip64 end of central directory record"
This contradicts the constant in your code which says that
private const uint ZIP64_END_OF_CENTRAL_DIRECTORY = 0x07064b50;
and is specifically searched for and throws the same Unknown Header exception.Now, the latter webpage says that signature is actually "zip64 end of central directory locator" and their example shows it directly in front of the 0x06064b50 entry.
So here is my interpretation:-
1) My sample ZIPX file has the 0x0606 header but not the 0x0706 header. This was creating using WinZip Pro BTW. Therefore I am guessing that the Locator 0x0706 is either optional or can be omitted when the next header is a zip64 End of CentralDirectory record.
2) I think your naming of 0x0706 is incorrect - it should be Zip64EndOfCentralDirectory__Locator__Signature not Record. This is confirmed by checking the DotNetZip source code.
3) The Zip64xxx headers can be ignored until zip64 support is added.
4) It is preferred to do this rather than throw an unknown header exception because otherwise the entire containing zip may be unreadable. In the sample code above, you can see I'm using Linq to order the Entries by their FilePath. Until I skipped these zip64 headers, I could not use this code because the exception stopped access to all of the entries.
The only changes I needed were these - case statements (including deleting the existing case ZIP64_END_OF_CENTRAL_DIRECTORY:) and an IgnoreHeader class:-
case 0x07064b50:
case 0x06064b50:
{
var entry = new IgnoreHeader((ZipHeaderType) (-1));
entry.Read(reader);
return entry;
}
internal class IgnoreHeader: ZipHeader
{
public IgnoreHeader(ZipHeaderType type): base(type)
{}
internal override void Read(BinaryReader reader)
{
}
internal override void Write(BinaryWriter writer)
{
throw new System.NotImplementedException();
}
}
↧