Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #187 from squid-box/dev
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
squid-box committed Mar 31, 2023
2 parents 3ec77d6 + 6a22efd commit b57b8d8
Show file tree
Hide file tree
Showing 46 changed files with 839 additions and 729 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
branches: [ "master" ]

env:
VERSION: '1.5.2.${{ github.run_number }}'
VERSION: '1.6.0.${{ github.run_number }}'

jobs:
build:
Expand Down
43 changes: 43 additions & 0 deletions SevenZip.Tests/SevenZipCompressorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,48 @@ public void CompressDifferentFormatsTest(CompressionMethod method)

Assert.IsTrue(File.Exists(TemporaryFile));
}

[Test]
public void AppendToArchiveWithEncryptedHeadersTest()
{
var compressor = new SevenZipCompressor()
{
ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMethod = CompressionMethod.Lzma2,
CompressionLevel = CompressionLevel.Normal,
EncryptHeaders = true,
};
compressor.CompressDirectory(@"TestData", TemporaryFile, "password");

compressor = new SevenZipCompressor
{
CompressionMode = CompressionMode.Append
};

compressor.CompressFilesEncrypted(TemporaryFile, "password", @"TestData\zip.zip");
}

[Test]
public void AppendEncryptedFileToStreamTest()
{
using var fileStream = new FileStream(TemporaryFile, FileMode.Create);

var compressor = new SevenZipCompressor
{
ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMethod = CompressionMethod.Lzma2,
CompressionMode = CompressionMode.Append,
ZipEncryptionMethod = ZipEncryptionMethod.Aes256,
CompressionLevel = CompressionLevel.Normal,
EncryptHeaders = true
};

compressor.CompressFilesEncrypted(fileStream, "password", @"TestData\zip.zip");

using var extractor = new SevenZipExtractor(TemporaryFile, "password");

Assert.AreEqual(1, extractor.FilesCount);
Assert.AreEqual("zip.zip", extractor.ArchiveFileNames[0]);
}
}
}
43 changes: 29 additions & 14 deletions SevenZip.Tests/SevenZipExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public void ExtractionWithCancellationTest()
{
using var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z");

tmp.FileExtractionStarted += (s, e) =>
tmp.FileExtractionStarted += (_, args) =>
{
if (e.FileInfo.Index == 2)
if (args.FileInfo.Index == 2)
{
e.Cancel = true;
args.Cancel = true;
}
};

Expand All @@ -95,11 +95,11 @@ public void ExtractionWithSkipTest()
{
using var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z");

tmp.FileExtractionStarted += (s, e) =>
tmp.FileExtractionStarted += (_, args) =>
{
if (e.FileInfo.Index == 1)
if (args.FileInfo.Index == 1)
{
e.Skip = true;
args.Skip = true;
}
};

Expand All @@ -119,6 +119,25 @@ public void ExtractionFromStreamTest()
Assert.AreEqual(3, Directory.GetFiles(OutputDirectory).Length);
}

[Test]
public void ExtractionFromStream_LeaveStreamOpenTest()
{
using var fileStream = new FileStream(@"TestData\multiple_files.7z", FileMode.Open);
using var extractor1 = new SevenZipExtractor(fileStream, leaveOpen: true);

extractor1.ExtractArchive(OutputDirectory);

Assert.IsTrue(fileStream.CanRead);

extractor1.Dispose();

using var extractor2 = new SevenZipExtractor(fileStream, leaveOpen: false);

extractor2.ExtractArchive(OutputDirectory);

Assert.IsFalse(fileStream.CanRead);
}

[Test]
public void ExtractionToStreamTest()
{
Expand Down Expand Up @@ -159,17 +178,13 @@ public void ThreadedExtractionTest()

var t1 = new Thread(() =>
{
using (var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z"))
{
tmp.ExtractArchive(destination1);
}
using var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z");
tmp.ExtractArchive(destination1);
});
var t2 = new Thread(() =>
{
using (var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z"))
{
tmp.ExtractArchive(destination2);
}
using var tmp = new SevenZipExtractor(@"TestData\multiple_files.7z");
tmp.ExtractArchive(destination2);
});

t1.Start();
Expand Down
Binary file modified SevenZip/7z.dll
Binary file not shown.
Binary file modified SevenZip/7z64.dll
Binary file not shown.
47 changes: 35 additions & 12 deletions SevenZip/ArchiveEmulationStreamProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,99 @@
/// </summary>
internal class ArchiveEmulationStreamProxy : Stream, IDisposable
{
/// <summary>
/// Gets the file offset.
/// </summary>
public int Offset { get; }

/// <summary>
/// The source wrapped stream.
/// </summary>
public Stream Source { get; }
private readonly bool _leaveOpen;

/// <summary>
/// Initializes a new instance of the ArchiveEmulationStream class.
/// </summary>
/// <param name="stream">The stream to wrap.</param>
/// <param name="offset">The stream offset.</param>
public ArchiveEmulationStreamProxy(Stream stream, int offset)
/// <param name="leaveOpen">Whether or not the stream should be closed after operation completes.</param>
public ArchiveEmulationStreamProxy(Stream stream, int offset, bool leaveOpen = false)
{
Source = stream;
Offset = offset;
Source.Position = offset;

_leaveOpen = leaveOpen;
}

/// <summary>
/// Gets the file offset.
/// </summary>
public int Offset { get; }

/// <summary>
/// The source wrapped stream.
/// </summary>
public Stream Source { get; }

/// <inheritdoc />
public override bool CanRead => Source.CanRead;

/// <inheritdoc />
public override bool CanSeek => Source.CanSeek;

/// <inheritdoc />
public override bool CanWrite => Source.CanWrite;

/// <inheritdoc />
public override void Flush()
{
Source.Flush();
}

/// <inheritdoc />
public override long Length => Source.Length - Offset;

/// <inheritdoc />
public override long Position
{
get => Source.Position - Offset;
set => Source.Position = value;
}

/// <inheritdoc />
public override int Read(byte[] buffer, int offset, int count)
{
return Source.Read(buffer, offset, count);
}

/// <inheritdoc />
public override long Seek(long offset, SeekOrigin origin)
{
return Source.Seek(origin == SeekOrigin.Begin ? offset + Offset : offset,
origin) - Offset;
}

/// <inheritdoc />
public override void SetLength(long value)
{
Source.SetLength(value);
}

/// <inheritdoc />
public override void Write(byte[] buffer, int offset, int count)
{
Source.Write(buffer, offset, count);
}

/// <inheritdoc />
public new void Dispose()
{
Source.Dispose();
if (!_leaveOpen)
{
Source.Dispose();
}
}

/// <inheritdoc />
public override void Close()
{
Source.Close();
if (!_leaveOpen)
{
Source.Close();
}
}
}
}
4 changes: 2 additions & 2 deletions SevenZip/ArchiveOpenCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal sealed class ArchiveOpenCallback : CallbackBase, IArchiveOpenCallback,
/// <param name="fileName">Volume file name.</param>
private void Init(string fileName)
{
if (!String.IsNullOrEmpty(fileName))
if (!string.IsNullOrEmpty(fileName))
{
_fileInfo = new FileInfo(fileName);
_volumeFileNames.Add(fileName);
Expand Down Expand Up @@ -98,7 +98,7 @@ public int GetProperty(ItemPropId propId, ref PropVariant value)
break;
case ItemPropId.Size:
value.VarType = VarEnum.VT_UI8;
value.UInt64Value = (UInt64) _fileInfo.Length;
value.UInt64Value = (ulong) _fileInfo.Length;
break;
case ItemPropId.Attributes:
value.VarType = VarEnum.VT_UI4;
Expand Down

0 comments on commit b57b8d8

Please sign in to comment.