/// <summary> /// Creates a <see cref="BlobIdentifierWithBlocks"/> from the bytes provided /// </summary> /// <param name="blob">The content against which the identifier should be created</param> /// <returns> /// A <see cref="BlobIdentifierWithBlocks"/> instance representing the unique identifier for binary the content. /// </returns> public static BlobIdentifierWithBlocks CalculateBlobIdentifierWithBlocks(this byte[] blob) { using (var stream = new MemoryStream(blob)) { return(VsoHash.CalculateBlobIdentifierWithBlocks(stream)); } }
/// <summary> /// Creates a <see cref="BlobIdentifierWithBlocks"/> from the stream provided /// </summary> /// <param name="blob">The content stream against which the identifier should be created</param> /// <returns> /// A <see cref="BlobIdentifierWithBlocks"/> instance representing the unique identifier for binary the content. /// </returns> public static BlobIdentifierWithBlocks CalculateBlobIdentifierWithBlocks(this Stream blob) { blob.Position = 0; var result = VsoHash.CalculateBlobIdentifierWithBlocks(blob); blob.Position = 0; return(result); }
/// <summary> /// Creates a <see cref="BlobIdentifierWithBlocks"/> from the stream provided /// </summary> /// <param name="blob">The content stream against which the identifier should be created</param> /// <returns> /// A <see cref="BlobIdentifierWithBlocks"/> instance representing the unique identifier for binary the content. /// </returns> public static async Task <BlobIdentifierWithBlocks> CalculateBlobIdentifierWithBlocksAsync(this Stream blob) { blob.Position = 0; var result = await VsoHash.CalculateBlobIdentifierWithBlocksAsync(blob).ConfigureAwait(false); blob.Position = 0; return(result); }
/// <inheritdoc /> protected override void HashCore(byte[] array, int ibStart, int cbSize) { while (cbSize > 0) { if (_currentOffset == _buffer.Length) { _blockHashes.Add(VsoHash.HashBlock(_buffer, _buffer.Length)); _currentOffset = 0; } int bytesToCopy = Math.Min(cbSize, _buffer.Length - _currentOffset); Buffer.BlockCopy(array, ibStart, _buffer, _currentOffset, bytesToCopy); _currentOffset += bytesToCopy; ibStart += bytesToCopy; cbSize -= bytesToCopy; } }
/// <inheritdoc /> protected override byte[] HashFinal() { var rollingId = new VsoHash.RollingBlobIdentifier(); // Flush out buffer if (_currentOffset != 0) { _blockHashes.Add(VsoHash.HashBlock(_buffer, _currentOffset)); } // if there are no blocks add an empty block if (_blockHashes.Count == 0) { _blockHashes.Add(VsoHash.HashBlock(new byte[] { }, 0)); } for (int i = 0; i < _blockHashes.Count - 1; i++) { rollingId.Update(_blockHashes[i]); } return(rollingId.Finalize(_blockHashes[_blockHashes.Count - 1]).Bytes); }
/// <summary> /// Creates a <see cref="BlobIdentifier"/> from the stream provided /// </summary> /// <param name="blob">The content bytes against which the identifier should be created.</param> /// <returns> /// A <see cref="BlobIdentifier"/> instance representing the unique identifier for binary the content. /// </returns> public static BlobIdentifier CalculateBlobIdentifier(this byte[] blob) { return(VsoHash.CalculateBlobIdentifier(blob)); }
private byte[] HashBlock(byte[] block, int lengthToHash) { VsoHash.HashBlockBytes(block, lengthToHash, _hashBuffer); return(_hashBuffer); }
private BlobBlockHash HashBlock(byte[] block, int lengthToHash) { return(VsoHash.HashBlock(block, lengthToHash)); }
private byte[] HashBlock(ReadOnlySpan <byte> block) { VsoHash.HashBlockBytes(block, _hashBuffer); return(_hashBuffer); }