public Task <BlobIdentifierWithBlocks> UploadLogToBlobstorageService(Stream blob, string hubName, Guid planId, int logId) { var blockBlobId = VsoHash.CalculateBlobIdentifierWithBlocks(blob); blob.Position = 0; using (var reader = new StreamReader(blob)) { var text = reader.ReadToEnd(); var lines = text.Split("\n"); UploadedLogBlobs.Add(blockBlobId, lines); } return(Task.FromResult(blockBlobId)); }
public async Task <BlobIdentifierWithBlocks> UploadLogToBlobstorageService(Stream blob, string hubName, Guid planId, int logId) { CheckConnection(); BlobIdentifier blobId = VsoHash.CalculateBlobIdentifierWithBlocks(blob).BlobId; // Since we read this while calculating the hash, the position needs to be reset before we send this blob.Position = 0; using (var blobClient = CreateArtifactsClient(_connection, default(CancellationToken))) { return(await blobClient.UploadBlocksForBlobAsync(blobId, blob, default(CancellationToken))); } }
public void CalculateBlobIdentifierFromArrayAndStreamUsingBlocksMatchEachOther() { using (Stream contentStream = MockBuilder.GetContentStream(VsoHash.BlockSize)) { byte[] content = MockBuilder.GetContent(VsoHash.BlockSize); string contentId1 = VsoHash.CalculateBlobIdentifierWithBlocks(contentStream).BlobId.ValueString; string contentId2 = VsoHash.CalculateBlobIdentifier(content).ValueString; if (contentId1 == null || contentId2 == null) { Assert.True(false, "inconclusive"); } Assert.Equal(contentId1, contentId2); } }
public void ChunkHashesMatchAndRollupToIdentifier() { var random = new Random(); TryWithDifferentSizes(testSize => { var bytes = new byte[testSize]; random.NextBytes(bytes); var blocks = new List <BlobBlockHash>(); var rollingId = new VsoHash.RollingBlobIdentifierWithBlocks(); BlobIdentifierWithBlocks blobIdentifierWithBlocks = null; for (int i = 0; i < testSize;) { int blockSize = Math.Min(testSize - i, VsoHash.BlockSize); var block = new byte[blockSize]; Array.Copy(bytes, i, block, 0, blockSize); BlobBlockHash blockHash = VsoHash.HashBlock(block, blockSize); blocks.Add(blockHash); i += blockSize; if (i < testSize) { rollingId.Update(blockHash); } else { blobIdentifierWithBlocks = rollingId.Finalize(blockHash); } } if (testSize == 0) { BlobBlockHash blockHash = VsoHash.HashBlock(new byte[] { }, 0); blocks.Add(blockHash); blobIdentifierWithBlocks = rollingId.Finalize(blockHash); } using (var byteStream = new MemoryStream(bytes)) { BlobIdentifierWithBlocks identifierWithBlocks = VsoHash.CalculateBlobIdentifierWithBlocks(byteStream); Assert.True(identifierWithBlocks.BlockHashes.SequenceEqual(blocks)); Assert.Equal(identifierWithBlocks, blobIdentifierWithBlocks); } }); }