You've already forked linux-packaging-mono
Imported Upstream version 4.4.0.40
Former-commit-id: 6427cc082e74df30afc535fd906a3494b74b0817
This commit is contained in:
@ -22,7 +22,7 @@ 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);
|
||||
outputStream.Write(new byte[] {80, 75, 1, 2, 0x14, 0, 0x0A, 0}, 0, 8);
|
||||
HeaderFlags flags = HeaderFlags.UTF8;
|
||||
if (!outputStream.CanSeek)
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ namespace SharpCompress.Writer.Zip
|
||||
byte[] encodedFilename = encoding.GetBytes(filename);
|
||||
|
||||
OutputStream.Write(BitConverter.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
|
||||
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version
|
||||
OutputStream.Write(new byte[] {20, 0}, 0, 2); //version
|
||||
HeaderFlags flags = encoding == Encoding.UTF8 ? HeaderFlags.UTF8 : (HeaderFlags)0;
|
||||
if (!OutputStream.CanSeek)
|
||||
{
|
||||
|
@ -114,6 +114,51 @@ namespace MonoTests.System.IO.Compression
|
||||
File.Delete ("test.zip");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ZipOpenAndReopenEntry()
|
||||
{
|
||||
try {
|
||||
File.Copy("archive.zip", "test.zip", overwrite: true);
|
||||
using (var archive = new ZipArchive(File.Open("test.zip", FileMode.Open),
|
||||
ZipArchiveMode.Update))
|
||||
{
|
||||
var entry = archive.GetEntry("foo.txt");
|
||||
Assert.IsNotNull(entry);
|
||||
|
||||
var stream = entry.Open();
|
||||
|
||||
try {
|
||||
stream = entry.Open();
|
||||
} catch (global::System.IO.IOException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
Assert.Fail();
|
||||
}
|
||||
} finally {
|
||||
File.Delete ("test.zip");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ZipOpenCloseAndReopenEntry()
|
||||
{
|
||||
File.Copy("archive.zip", "test.zip", overwrite: true);
|
||||
using (var archive = new ZipArchive(File.Open("test.zip", FileMode.Open),
|
||||
ZipArchiveMode.Update))
|
||||
{
|
||||
var entry = archive.GetEntry("foo.txt");
|
||||
Assert.IsNotNull(entry);
|
||||
|
||||
var stream = entry.Open();
|
||||
stream.Dispose();
|
||||
stream = entry.Open();
|
||||
}
|
||||
|
||||
File.Delete ("test.zip");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ZipGetEntryDeleteReadMode()
|
||||
{
|
||||
|
@ -29,10 +29,96 @@ using SharpCompress.Archive;
|
||||
|
||||
namespace System.IO.Compression
|
||||
{
|
||||
internal class ZipArchiveEntryStream : Stream, IDisposable
|
||||
{
|
||||
private readonly ZipArchiveEntry entry;
|
||||
private readonly Stream stream;
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return stream.CanRead;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
return stream.CanSeek;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return stream.CanWrite;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
return stream.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
return stream.Position;
|
||||
}
|
||||
set {
|
||||
stream.Position = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ZipArchiveEntryStream(ZipArchiveEntry entry, Stream stream)
|
||||
{
|
||||
this.entry = entry;
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
stream.Flush();
|
||||
}
|
||||
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
return stream.Seek(offset, origin);
|
||||
}
|
||||
|
||||
public override void SetLength (long value)
|
||||
{
|
||||
stream.SetLength(value);
|
||||
}
|
||||
|
||||
public override int Read (byte[] buffer, int offset, int count)
|
||||
{
|
||||
return stream.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override void Write (byte[] buffer, int offset, int count)
|
||||
{
|
||||
stream.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
entry.openStream = null;
|
||||
stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ZipArchiveEntry
|
||||
{
|
||||
readonly SharpCompress.Archive.Zip.ZipArchiveEntry entry;
|
||||
private Stream openStream;
|
||||
internal ZipArchiveEntryStream openStream;
|
||||
private bool wasDeleted;
|
||||
|
||||
internal ZipArchiveEntry(ZipArchive archive, SharpCompress.Archive.Zip.ZipArchiveEntry entry)
|
||||
@ -112,7 +198,7 @@ namespace System.IO.Compression
|
||||
if (Archive.Mode == ZipArchiveMode.Create && openStream != null)
|
||||
throw new IOException("The archive for this entry was opened with the Create mode, and this entry has already been written to.");
|
||||
|
||||
openStream = entry.OpenEntryStream();
|
||||
openStream = new ZipArchiveEntryStream(this, entry.OpenEntryStream());
|
||||
|
||||
return openStream;
|
||||
}
|
||||
|
Reference in New Issue
Block a user