Compare commits

..

4 Commits

Author SHA1 Message Date
Adam Hathcock
84704e5ce2 Release packaging for 0.10.3 2013-12-15 11:42:54 +00:00
Adam Hathcock
059fe1f545 Test for previous change 2013-12-15 11:16:59 +00:00
Adam Hathcock
fe8c6aec5f Ensure adding always disposes 2013-12-15 11:16:48 +00:00
Adam Hathcock
3ab38fbfc2 If the requested amount of bytes was not read, assume end of stream 2013-11-24 09:40:38 +00:00
9 changed files with 54 additions and 21 deletions

View File

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

View File

@@ -21,6 +21,10 @@ TODOs (always lots):
* Zip64
* Multi-volume Zip support.
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.

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -184,16 +185,32 @@ namespace SharpCompress.Test
[TestMethod]
public void Zip_Create_New()
{
string scratchPath = Path.Combine(SCRATCH_FILES_PATH, "Zip.deflate.noEmptyDirs.zip");
base.ResetScratch();
foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories))
{
var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length);
if (newFileName.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
newFileName = newFileName.Substring(1);
}
newFileName = Path.Combine(SCRATCH_FILES_PATH, newFileName);
var newDir = Path.GetDirectoryName(newFileName);
if (!Directory.Exists(newDir))
{
Directory.CreateDirectory(newDir);
}
File.Copy(file, newFileName);
}
string scratchPath = Path.Combine(SCRATCH2_FILES_PATH, "Zip.deflate.noEmptyDirs.zip");
string unmodified = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.noEmptyDirs.zip");
base.ResetScratch();
using (var archive = ZipArchive.Create())
{
archive.AddAllFromDirectory(ORIGINAL_FILES_PATH);
archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
archive.SaveTo(scratchPath, CompressionType.Deflate);
}
CompareArchivesByPath(unmodified, scratchPath);
Directory.Delete(SCRATCH_FILES_PATH, true);
}
[TestMethod]

View File

@@ -118,7 +118,7 @@ namespace SharpCompress.Archive
private bool disposed;
public void Dispose()
public virtual void Dispose()
{
if (!disposed)
{

View File

@@ -117,5 +117,13 @@ namespace SharpCompress.Archive
protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
IEnumerable<TEntry> oldEntries, IEnumerable<TEntry> newEntries);
public override void Dispose()
{
base.Dispose();
newEntries.Cast<Entry>().ForEach(x => x.Close());
removedEntries.Cast<Entry>().ForEach(x => x.Close());
modifiedEntries.Cast<Entry>().ForEach(x => x.Close());
}
}
}

View File

@@ -8,16 +8,17 @@ namespace SharpCompress.Archive.Zip
{
internal class ZipWritableArchiveEntry : ZipArchiveEntry
{
private string path;
private long size;
private DateTime? lastModified;
private bool closeStream;
private readonly string path;
private readonly long size;
private readonly DateTime? lastModified;
private readonly bool closeStream;
private bool isDisposed;
internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
DateTime? lastModified, bool closeStream)
: base(archive, null)
{
this.Stream = stream;
Stream = stream;
this.path = path;
this.size = size;
this.lastModified = lastModified;
@@ -93,9 +94,10 @@ namespace SharpCompress.Archive.Zip
internal override void Close()
{
if (closeStream)
if (closeStream && !isDisposed)
{
Stream.Dispose();
isDisposed = true;
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace SharpCompress.Common
{
public abstract class Entry : SharpCompress.Common.IEntry
public abstract class Entry : IEntry
{
internal bool IsSolid { get; set; }

View File

@@ -21,14 +21,12 @@ namespace SharpCompress.IO
public override int Read()
{
CurrentReadByteCount += 4;
return base.Read();
throw new NotImplementedException();
}
public override int Read(byte[] buffer, int index, int count)
{
CurrentReadByteCount += count;
return base.Read(buffer, index, count);
throw new NotImplementedException();
}
public override int Read(char[] buffer, int index, int count)
@@ -38,8 +36,7 @@ namespace SharpCompress.IO
public override bool ReadBoolean()
{
CurrentReadByteCount++;
return base.ReadBoolean();
return BitConverter.ToBoolean(ReadBytes(1), 0);
}
public override byte ReadByte()
@@ -50,7 +47,12 @@ namespace SharpCompress.IO
public override byte[] ReadBytes(int count)
{
CurrentReadByteCount += count;
return base.ReadBytes(count);
var bytes = base.ReadBytes(count);
if (bytes.Length != count)
{
throw new EndOfStreamException(string.Format("Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}", count, bytes.Length));
}
return bytes;
}
public override char ReadChar()

View File

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