public override string WriteTempPackFile(HttpGitObjects.GitEndPointResponseData response) { Debug.Assert(response.Stream != null, "WriteTempPackFile should not receive a null stream"); using (response.Stream) using (StreamReader reader = new StreamReader(response.Stream)) { // Return "file contents" as "file name". Weird, but proves we got the right thing. return(reader.ReadToEnd()); } }
private RetryWrapper <HttpGitObjects.GitObjectTaskResult> .CallbackResult WriteObjectOrPackAsync( BlobDownloadRequest request, int tryCount, HttpGitObjects.GitEndPointResponseData response, HashSet <string> successfulDownloads = null) { string fileName = null; switch (response.ContentType) { case HttpGitObjects.ContentType.LooseObject: string sha = request.ObjectIds.First(); fileName = this.gitObjects.WriteLooseObject( this.enlistment.WorkingDirectoryRoot, response.Stream, sha); this.AvailableObjects.Add(sha); break; case HttpGitObjects.ContentType.PackFile: fileName = this.gitObjects.WriteTempPackFile(response); this.AvailablePacks.Add(new IndexPackRequest(fileName, request)); break; case HttpGitObjects.ContentType.BatchedLooseObjects: // To reduce allocations, reuse the same buffer when writing objects in this batch byte[] bufToCopyWith = new byte[StreamUtil.DefaultCopyBufferSize]; OnLooseObject onLooseObject = (objectStream, sha1) => { this.gitObjects.WriteLooseObject( this.enlistment.WorkingDirectoryRoot, objectStream, sha1, bufToCopyWith); this.AvailableObjects.Add(sha1); if (successfulDownloads != null) { successfulDownloads.Add(sha1); } // This isn't strictly correct because we don't add object header bytes, // just the actual compressed content length, but we expect the amount of // header data to be negligible compared to the objects themselves. Interlocked.Add(ref this.bytesDownloaded, objectStream.Length); }; new BatchedLooseObjectDeserializer(response.Stream, onLooseObject).ProcessObjects(); break; } if (fileName != null) { // NOTE: If we are writing a file as part of this method, the only case // where it's not expected to exist is when running unit tests FileInfo info = new FileInfo(fileName); if (info.Exists) { Interlocked.Add(ref this.bytesDownloaded, info.Length); } else { return(new RetryWrapper <HttpGitObjects.GitObjectTaskResult> .CallbackResult( new HttpGitObjects.GitObjectTaskResult(false))); } } return(new RetryWrapper <HttpGitObjects.GitObjectTaskResult> .CallbackResult( new HttpGitObjects.GitObjectTaskResult(true))); }