Skip to content

Commit

Permalink
Fix after merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Apr 17, 2023
1 parent a74062c commit 2545fea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
35 changes: 35 additions & 0 deletions src/StaticWebAssetsSdk/Tasks/FileHasher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;

public static class FileHasher
{
public static string GetFileHash(string filePath)
{
using var hash = SHA256.Create();
var bytes = Encoding.UTF8.GetBytes(filePath);
var hashBytes = hash.ComputeHash(bytes);
return ToBase36(hashBytes);
}

private static string ToBase36(byte[] hash)
{
const string chars = "0123456789abcdefghijklmnopqrstuvwxyz";

var result = new char[10];
var dividend = BigInteger.Abs(new BigInteger(hash.AsSpan().Slice(0, 9).ToArray()));
for (var i = 0; i < 10; i++)
{
dividend = BigInteger.DivRem(dividend, 36, out var remainder);
result[i] = chars[(int)remainder];
}

return new string(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@
<Compile Include="..\..\RazorSdk\Tasks\DotnetToolTask.cs">
<Link>Shared\DotnetToolTask.cs</Link>
</Compile>
<Compile Include="..\..\WasmSdk\Tasks\FileHasher.cs">
<Link>Shared\FileHasher.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/StaticWebAssetsSdk/Tasks/ResolveCompressedAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.NET.Sdk.WebAssembly;

namespace Microsoft.AspNetCore.StaticWebAssets.Tasks;

Expand Down

0 comments on commit 2545fea

Please sign in to comment.