Skip to content

Commit 05c43d0

Browse files
authored
Merge pull request #52 from jonathanpeppers/arraypool-fix
Fix for System.Buffers.ArrayPool
2 parents 5d1985e + ebe04d2 commit 05c43d0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

LibZipSharp.UnitTest/ZipTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,24 @@ public void AddStreamDateCheck ()
138138
Assert.AreEqual (date, WithoutMilliseconds (entry.ModificationTime), $"Check 1 {WithoutMilliseconds (entry.ModificationTime)} != {date}");
139139
}
140140
}
141+
142+
[Test]
143+
public void SmallTextFile ()
144+
{
145+
var zipStream = new MemoryStream ();
146+
var encoding = Encoding.UTF8;
147+
using (var zip = ZipArchive.Create (zipStream)) {
148+
zip.AddEntry ("foo", "bar", encoding);
149+
}
150+
using (var zip = ZipArchive.Open (zipStream)) {
151+
var entry = zip.ReadEntry ("foo");
152+
Assert.IsNotNull (entry, "Entry 'foo' should exist!");
153+
using (var stream = new MemoryStream ()) {
154+
entry.Extract (stream);
155+
stream.Position = 0;
156+
Assert.AreEqual ("bar", encoding.GetString (stream.ToArray ()));
157+
}
158+
}
159+
}
141160
}
142161
}

ZipArchive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ internal static unsafe Int64 stream_callback (IntPtr state, IntPtr data, UInt64
751751
try {
752752
Marshal.Copy (data, buffer, 0, length);
753753
stream.Write (buffer, 0, length);
754-
return buffer.Length;
754+
return length;
755755
} finally {
756756
ArrayPool<byte>.Shared.Return (buffer);
757757
}

0 commit comments

Comments
 (0)