8000 Add a test exercising the Blob.ContentStream property · dotjosh/libgit2sharp@7f65f29 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f65f29

Browse files
committed
Add a test exercising the Blob.ContentStream property
1 parent 1204fdf commit 7f65f29

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,51 @@ public void CanReadBlobStream()
6868
}
6969
}
7070
}
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+
}
71117
}
72118
}

0 commit comments

Comments
 (0)
0