@@ -36,19 +36,37 @@ protected abstract OdbBackendOperations SupportedOperations
36
36
/// Call this method from your implementations of Read and ReadPrefix to allocate a buffer in
37
37
/// which to return the object's data.
38
38
/// </summary>
39
- /// <param name="bytes">Number of bytes to allocate</param>
40
- /// <returns>An Stream for you to write to and then return. Do not dispose this object before returning it.</returns>
41
- protected unsafe UnmanagedMemoryStream Allocate ( long bytes )
39
+ /// <param name="bytes">The bytes to be copied to the stream.</param>
40
+ /// <returns>
41
+ /// A Stream already filled with the content of provided the byte array.
42
+ /// Do not dispose this object before returning it.
43
+ /// </returns>
44
+ protected UnmanagedMemoryStream AllocateAndBuildFrom ( byte [ ] bytes )
42
45
{
43
- if ( bytes < 0 ||
44
- ( UIntPtr . Size == sizeof ( int ) && bytes > int . MaxValue ) )
46
+ var stream = Allocate ( bytes . Length ) ;
47
+
48
+ stream . Write ( bytes , 0 , bytes . Length ) ;
49
+
50
+ return stream ;
51
+ }
52
+
53
+ /// <summary>
54
+ /// Call this method from your implementations of Read and ReadPrefix to allocate a buffer in
55
+ /// which to return the object's data.
56
+ /// </summary>
57
+ /// <param name="size">Number of bytes to allocate</param>
58
+ /// <returns>A Stream for you to write to and then return. Do not dispose this object before returning it.</returns>
59
+ protected unsafe UnmanagedMemoryStream Allocate ( long size )
60
+ {
61
+ if ( size < 0 ||
62
+ ( UIntPtr . Size == sizeof ( int ) && size > int . MaxValue ) )
45
63
{
46
- throw new ArgumentOutOfRangeException ( "bytes " ) ;
64
+ throw new ArgumentOutOfRangeException ( "size " ) ;
47
65
}
48
66
49
- IntPtr buffer = Proxy . git_odb_backend_malloc ( this . GitOdbBackendPointer , new UIntPtr ( ( ulong ) bytes ) ) ;
67
+ IntPtr buffer = Proxy . git_odb_backend_malloc ( this . GitOdbBackendPointer , new UIntPtr ( ( ulong ) size ) ) ;
50
68
51
- return new UnmanagedMemoryStream ( ( byte * ) buffer , 0 , bytes , FileAccess . ReadWrite ) ;
69
+ return new UnmanagedMemoryStream ( ( byte * ) buffer , 0 , size , FileAccess . ReadWrite ) ;
52
70
}
53
71
54
72
/// <summary>
0 commit comments