@@ -68,5 +68,51 @@ public void CanReadBlobStream()
68
68
}
69
69
}
70
70
}
71
+
72
+ public static void CopyStream ( Stream input , Stream output )
73
+ {
74
+ var buffer = new byte [ 8 * 1024 ] ;
75
+ int len ;
76
+ while ( ( len = input . Read ( buffer , 0 , buffer . Length ) ) > 0 )
77
+ {
78
+ output . Write ( buffer , 0 , len ) ;
79
+ }
80
+ }
81
+
82
+ [ Test ]
83
+ public void CanStageAFileGeneratedFromABlobContentStream ( )
84
+ {
85
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
86
+
87
+ using ( Repository repo = Repository . Init ( scd . DirectoryPath ) )
88
+ {
89
+ for ( int i = 0 ; i < 5 ; i ++ )
90
+ {
91
+ var sb = new StringBuilder ( ) ;
92
+ for ( int j = 0 ; j < 2000 ; j ++ )
93
+ {
94
+ sb . Append ( ( ( i + 1 ) * ( j + 1 ) ) . ToString ( "X8" ) ) ;
95
+ }
96
+ File . AppendAllText ( Path . Combine ( repo . Info . WorkingDirectory , "small.txt" ) , sb . ToString ( ) ) ;
97
+ }
98
+
99
+ repo . Index . Stage ( "small.txt" ) ;
100
+ IndexEntry entry = repo . Index [ "small.txt" ] ;
101
+ entry . Id . Sha . ShouldEqual ( "baae1fb3760a73481ced1fa03dc15614142c19ef" ) ;
102
+
103
+ var blob = repo . Lookup < Blob > ( entry . Id . Sha ) ;
104
+
105
+ using ( Stream stream = blob . ContentStream )
106
+ using ( Stream file = File . OpenWrite ( Path . Combine ( repo . Info . WorkingDirectory , "small.fromblob.txt" ) ) )
107
+ {
108
+ CopyStream ( stream , file ) ;
109
+ }
110
+
111
+ repo . Index . Stage ( "small.fromblob.txt" ) ;
112
+ IndexEntry newentry = repo . Index [ "small.fromblob.txt" ] ;
113
+
114
+ newentry . Id . Sha . ShouldEqual ( "baae1fb3760a73481ced1fa03dc15614142c19ef" ) ;
115
+ }
116
+ }
71
117
}
72
118
}
0 commit comments