mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-07 13:44:36 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84704e5ce2 | ||
|
|
059fe1f545 | ||
|
|
fe8c6aec5f | ||
|
|
3ab38fbfc2 |
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace SharpCompress.Archive
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public void Dispose()
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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")]
|
||||
Reference in New Issue
Block a user