Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for System.Buffers.ArrayPool #52

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LibZipSharp.UnitTest/ZipTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,24 @@ public void AddStreamDateCheck ()
Assert.AreEqual (date, WithoutMilliseconds (entry.ModificationTime), $"Check 1 {WithoutMilliseconds (entry.ModificationTime)} != {date}");
}
}

[Test]
public void SmallTextFile ()
{
var zipStream = new MemoryStream ();
var encoding = Encoding.UTF8;
using (var zip = ZipArchive.Create (zipStream)) {
zip.AddEntry ("foo", "bar", encoding);
}
using (var zip = ZipArchive.Open (zipStream)) {
var entry = zip.ReadEntry ("foo");
Assert.IsNotNull (entry, "Entry 'foo' should exist!");
using (var stream = new MemoryStream ()) {
entry.Extract (stream);
stream.Position = 0;
Assert.AreEqual ("bar", encoding.GetString (stream.ToArray ()));
}
}
}
}
}
2 changes: 1 addition & 1 deletion ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
try {
Marshal.Copy (data, buffer, 0, length);
stream.Write (buffer, 0, length);
return buffer.Length;
return length;
} finally {
ArrayPool<byte>.Shared.Return (buffer);
}
Expand Down