Compare commits

...

14 Commits

Author SHA1 Message Date
Adam Hathcock
bb930da2f1 0.11.6 packaging 2016-04-07 09:44:28 +01:00
Adam Hathcock
732e352261 Merge pull request #138 from adamhathcock/leaveopen_writers
Leave open writers
2016-04-06 08:17:09 +01:00
Adam Hathcock
8f2ada3f20 Update README.md 2016-03-31 10:10:20 +01:00
Adam Hathcock
762381fac6 Explicit finish for BZip2 writing 2016-03-31 08:54:23 +01:00
Adam Hathcock
c440fdf88d Give writers leaveOpen option 2016-03-30 20:18:46 +01:00
Adam Hathcock
7f3f6bb135 Merge pull request #136 from zentron/master
Fix for `System.IO.Compression` created empty directory in zip
2016-03-03 13:13:59 +00:00
Rob
cb7853174d Fix for System.IO.Compression created empty directory in zip 2016-03-03 14:40:14 +10:00
Adam Hathcock
ef8575a107 Matching 77b034cbe7 to have 20 as the version made by 2016-02-26 09:22:23 +00:00
Adam Hathcock
6f3f82e0ad Merge pull request #129 from benshoof/tar-globalextendedheader
Support tars with global extended headers
2016-02-18 07:18:55 +00:00
benshoof
7b1609abe2 Support tars with global extended headers 2016-02-17 15:39:17 -09:00
Adam Hathcock
ee5e3fbc1d Update to 0.11.5 2016-02-13 09:17:29 +00:00
Adam Hathcock
d13b2ad073 Do less than equals 2016-02-13 09:16:43 +00:00
Adam Hathcock
e9a7efc371 Merge pull request #127 from eklann/bugfix-incomplete-rar
Fixed bug triggered by incomplete rar file.
2016-02-10 19:38:10 +00:00
Josef Eklann
9b8ddda191 Fixed bug triggered by incomplete rar file. 2016-02-10 14:56:05 +01:00
14 changed files with 110 additions and 71 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>sharpcompress</id>
<version>0.11.4</version>
<version>0.11.6</version>
<title>SharpCompress - Pure C# Decompression/Compression</title>
<authors>Adam Hathcock</authors>
<owners>Adam Hathcock</owners>

105
README.md
View File

@@ -1,74 +1,89 @@
SharpCompress
=============
# SharpCompress
SharpCompress is a compression library for .NET/Mono/Silverlight/WP7 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented.
The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).
A Simple Request
## Need Help?
Post Issues on Github!
Check the [Supported Formats](https://github.com/adamhathcock/sharpcompress/wiki/Supported-Formats) and [basic samples.](https://github.com/adamhathcock/sharpcompress/wiki/API-Examples)
## A Simple Request
Hi everyone. I hope you're using SharpCompress and finding it useful. Please give me feedback on what you'd like to see changed especially as far as usability goes. New feature suggestions are always welcome as well. I would also like to know what projects SharpCompress is being used in. I like seeing how it is used to give me ideas for future versions. Thanks!
Please do not email me directly to ask for help. If you think there is a real issue, please report it here.
Want to contribute?
## Want to contribute?
I'm always looking for help or ideas. Please submit code or email with ideas. Unfortunately, just letting me know you'd like to help is not enough because I really have no overall plan of what needs to be done. I'll definitely accept code submissions and add you as a member of the project!
TODOs (always lots):
## TODOs (always lots)
* RAR 5 support
* 7Zip writing
* Zip64
* Multi-volume Zip support.
In-Progress:
==============
- RAR5 support
- DNX/NET Core support
- xproj targeting
## In-Progress
Version 0.11.4:
==============
- SharpCompress is now endian neutral (matters for Mono platforms)
- Fix for Inflate (need to change implementation)
- Fixes for RAR detection
* RAR5 support
* DNX/NET Core support
* xproj targeting
Version 0.11.1:
==============
- Added Cancel on IReader
- Removed .NET 2.0 support and LinqBridge dependency
## Version Log
Version 0.11:
==============
- Been over a year, contains mainly fixes from contributors!
- Possible breaking change: ArchiveEncoding is UTF8 by default now.
- TAR supports writing long names using longlink
- RAR Protect Header added
### Version 0.11.6
Version 0.10.3:
==============
- Finally fixed Disposal issue when creating a new archive with the Archive API
* Bug fix for global header in Tar
* Writers now have a leaveOpen `bool` overload. They won't close streams if not-requested to.
Version 0.10.2:
==============
- Fixed Rar Header reading for invalid extended time headers.
- Windows Store assembly is now strong named
- Known issues with Long Tar names being worked on
- Updated to VS2013
- Portable targets SL5 and Windows Phone 8 (up from SL4 and WP7)
### Version 0.11.5
Version 0.10.1:
==============
- Fixed 7Zip extraction performance problem
* Bug fix in Skip method
Version 0.10:
==============
- Added support for RAR Decryption (thanks to https://github.com/hrasyid)
- Embedded some BouncyCastle crypto classes to allow RAR Decryption and Winzip AES Decryption in Portable and Windows Store DLLs
- Built in Release (I think)
### Version 0.11.4
Some Help/Discussion:
https://sharpcompress.codeplex.com/discussions
* SharpCompress is now endian neutral (matters for Mono platforms)
* Fix for Inflate (need to change implementation)
* Fixes for RAR detection
### Version 0.11.1
* Added Cancel on IReader
* Removed .NET 2.0 support and LinqBridge dependency
### Version 0.11
* Been over a year, contains mainly fixes from contributors!
* Possible breaking change: ArchiveEncoding is UTF8 by default now.
* TAR supports writing long names using longlink
* RAR Protect Header added
### Version 0.10.3
* Finally fixed Disposal issue when creating a new archive with the Archive API
### Version 0.10.2
* Fixed Rar Header reading for invalid extended time headers.
* Windows Store assembly is now strong named
* Known issues with Long Tar names being worked on
* Updated to VS2013
* Portable targets SL5 and Windows Phone 8 (up from SL4 and WP7)
### Version 0.10.1
* Fixed 7Zip extraction performance problem
### Version 0.10:
* Added support for RAR Decryption (thanks to https://github.com/hrasyid)
* Embedded some BouncyCastle crypto classes to allow RAR Decryption and Winzip AES Decryption in Portable and Windows Store DLLs
* Built in Release (I think)
Some Help/Discussion: https://sharpcompress.codeplex.com/discussions
7Zip implementation based on: https://code.google.com/p/managed-lzma/

View File

@@ -1,5 +1,7 @@
using System.IO;
using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.IO;
using SharpCompress.Reader;
using SharpCompress.Writer;
@@ -18,9 +20,15 @@ namespace SharpCompress.Test
{
ResetScratch();
using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive)))
using (var writer = WriterFactory.Open(stream, type, compressionType))
{
writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);
using (var writer = WriterFactory.Open(stream, type, compressionType, true))
{
writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories);
}
if (!stream.CanWrite)
{
throw new InvalidOperationException();
}
}
CompareArchivesByPath(Path.Combine(SCRATCH2_FILES_PATH, archive),
Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst));

View File

@@ -22,6 +22,7 @@ namespace SharpCompress.Common.Tar.Headers
LongName = (byte) 'L',
SparseFile = (byte) 'S',
VolumeHeader = (byte) 'V',
GlobalExtendedHeader = (byte) 'g',
}
internal class TarHeader

View File

@@ -16,7 +16,17 @@ namespace SharpCompress.Common.Zip.Headers
internal bool IsDirectory
{
get { return Name.EndsWith("/"); }
get
{
if (Name.EndsWith("/"))
return true;
//.NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers
return CompressedSize == 0
&& UncompressedSize == 0
&& Name.EndsWith("\\");
}
}
protected string DecodeString(byte[] str)

View File

@@ -27,6 +27,11 @@ namespace SharpCompress.Compressor.BZip2
this.stream = new CBZip2InputStream(stream, decompressContacted, leaveOpen);
}
}
public void Finish()
{
(this.stream as CBZip2OutputStream)?.Finish();
}
protected override void Dispose(bool disposing)
{

View File

@@ -53,7 +53,7 @@ namespace SharpCompress.Reader
if (BZip2Stream.IsBZip2(rewindableStream))
{
rewindableStream.Rewind(false);
BZip2Stream testStream = new BZip2Stream(rewindableStream, CompressionMode.Decompress, false);
BZip2Stream testStream = new BZip2Stream(rewindableStream, CompressionMode.Decompress, true);
if (TarArchive.IsTarFile(testStream))
{
rewindableStream.Rewind(true);

View File

@@ -146,7 +146,7 @@ namespace SharpCompress
readCount = (int)advanceAmount;
}
read = source.Read(buffer, 0, readCount);
if (read < 0)
if (read <= 0)
{
break;
}

View File

@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("Copyright © Adam Hathcock")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("0.11.3.0")]
[assembly: AssemblyFileVersion("0.11.3.0")]
[assembly: AssemblyVersion("0.11.6.0")]
[assembly: AssemblyFileVersion("0.11.6.0")]

View File

@@ -1,7 +1,6 @@
using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.Compressor;
using SharpCompress.Compressor.Deflate;
@@ -11,10 +10,10 @@ namespace SharpCompress.Writer.GZip
{
private bool wroteToStream;
public GZipWriter(Stream destination)
public GZipWriter(Stream destination, bool leaveOpen = false)
: base(ArchiveType.GZip)
{
InitalizeStream(new GZipStream(destination, CompressionMode.Compress, true), true);
InitalizeStream(new GZipStream(destination, CompressionMode.Compress, leaveOpen), !leaveOpen);
}
protected override void Dispose(bool isDisposing)

View File

@@ -10,7 +10,7 @@ namespace SharpCompress.Writer.Tar
{
public class TarWriter : AbstractWriter
{
public TarWriter(Stream destination, CompressionInfo compressionInfo)
public TarWriter(Stream destination, CompressionInfo compressionInfo, bool leaveOpen = false)
: base(ArchiveType.Tar)
{
if (!destination.CanWrite)
@@ -23,12 +23,12 @@ namespace SharpCompress.Writer.Tar
break;
case CompressionType.BZip2:
{
destination = new BZip2Stream(destination, CompressionMode.Compress, false);
destination = new BZip2Stream(destination, CompressionMode.Compress, leaveOpen);
}
break;
case CompressionType.GZip:
{
destination = new GZipStream(destination, CompressionMode.Compress, false);
destination = new GZipStream(destination, CompressionMode.Compress, leaveOpen);
}
break;
default:
@@ -36,7 +36,7 @@ namespace SharpCompress.Writer.Tar
throw new InvalidFormatException("Tar does not support compression: " + compressionInfo.Type);
}
}
InitalizeStream(destination, false);
InitalizeStream(destination, !leaveOpen);
}
public override void Write(string filename, Stream source, DateTime? modificationTime)
@@ -91,7 +91,7 @@ namespace SharpCompress.Writer.Tar
{
PadTo512(0, true);
PadTo512(0, true);
OutputStream.Dispose(); // required when bzip2 compression is used
(OutputStream as BZip2Stream)?.Finish(); // required when bzip2 compression is used
}
base.Dispose(isDisposing);
}

View File

@@ -9,15 +9,15 @@ namespace SharpCompress.Writer
{
public static class WriterFactory
{
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType)
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionType compressionType, bool leaveOpen = false)
{
return Open(stream, archiveType, new CompressionInfo
{
Type = compressionType
});
}, leaveOpen);
}
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionInfo compressionInfo)
public static IWriter Open(Stream stream, ArchiveType archiveType, CompressionInfo compressionInfo, bool leaveOpen = false)
{
switch (archiveType)
{
@@ -27,15 +27,15 @@ namespace SharpCompress.Writer
{
throw new InvalidFormatException("GZip archives only support GZip compression type.");
}
return new GZipWriter(stream);
return new GZipWriter(stream, leaveOpen);
}
case ArchiveType.Zip:
{
return new ZipWriter(stream, compressionInfo, null);
return new ZipWriter(stream, compressionInfo, null, leaveOpen);
}
case ArchiveType.Tar:
{
return new TarWriter(stream, compressionInfo);
return new TarWriter(stream, compressionInfo, leaveOpen);
}
default:
{

View File

@@ -23,7 +23,8 @@ namespace SharpCompress.Writer.Zip
byte[] encodedFilename = Encoding.UTF8.GetBytes(FileName);
byte[] encodedComment = Encoding.UTF8.GetBytes(Comment);
outputStream.Write(new byte[] {80, 75, 1, 2, 0x3F, 0, 0x0A, 0}, 0, 8);
//constant sig, then version made by, compabitility, then version to extract
outputStream.Write(new byte[] {80, 75, 1, 2, 0x14, 0, 0x0A, 0}, 0, 8);
HeaderFlags flags = HeaderFlags.UTF8;
if (!outputStream.CanSeek)
{

View File

@@ -24,13 +24,13 @@ namespace SharpCompress.Writer.Zip
private readonly string zipComment;
private long streamPosition;
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment)
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment, bool leaveOpen = false)
: base(ArchiveType.Zip)
{
this.zipComment = zipComment ?? string.Empty;
this.zipCompressionInfo = new ZipCompressionInfo(compressionInfo);
InitalizeStream(destination, false);
InitalizeStream(destination, !leaveOpen);
}
protected override void Dispose(bool isDisposing)