Skip to content
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
9 changes: 1 addition & 8 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ public static byte[] git_blob_rawcontent(RepositorySafeHandle repo, ObjectId id,

public static UnmanagedMemoryStream git_blob_rawcontent_stream(RepositorySafeHandle repo, ObjectId id, Int64 size)
{
using (var obj = new ObjectSafeWrapper(id, repo))
{
IntPtr ptr = NativeMethods.git_blob_rawcontent(obj.ObjectPtr);
unsafe
{
return new UnmanagedMemoryStream((byte*)ptr.ToPointer(), size);
}
}
return new RawContentStream(id, repo, NativeMethods.git_blob_rawcontent, size);
}

public static Int64 git_blob_rawsize(GitObjectSafeHandle obj)
Expand Down
32 changes: 32 additions & 0 deletions LibGit2Sharp/Core/RawContentStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;

namespace LibGit2Sharp.Core
{
internal class RawContentStream : UnmanagedMemoryStream
{
readonly ObjectSafeWrapper wrapper;

internal RawContentStream(ObjectId id, RepositorySafeHandle repo,
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length)
: this(new ObjectSafeWrapper(id, repo), bytePtrProvider, length)
{
}

unsafe RawContentStream(ObjectSafeWrapper wrapper,
Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length)
: base((byte *)bytePtrProvider(wrapper.ObjectPtr).ToPointer(), length)
{
this.wrapper = wrapper;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
wrapper.SafeDispose();
}
}
}

1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<Compile Include="TreeEntry.cs" />
<Compile Include="TreeEntryDefinition.cs" />
<Compile Include="VoidReference.cs" />
<Compile Include="Core\RawContentStream.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
Expand Down