Skip to content

Commit f7422f3

Browse files
Cleanup and fix tests
1 parent 68eb805 commit f7422f3

File tree

6 files changed

+39
-21
lines changed

6 files changed

+39
-21
lines changed

Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageReference Update="Azure.Storage.Blobs" Version="12.4.0" />
2626
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
2727
<PackageReference Update="MinVer" PrivateAssets="All" Version="2.3.0" />
28-
<PackageReference Update="SixLabors.ImageSharp" Version="1.0.0" />
28+
<PackageReference Update="SixLabors.ImageSharp" Version="1.0.1" />
2929
</ItemGroup>
3030

3131
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">

src/ImageSharp.Web.Providers.Azure/Resolvers/AzureBlobStorageImageResolver.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public async Task<ImageMetadata> GetMetaDataAsync()
3232

3333
/// <inheritdoc/>
3434
public async Task<Stream> OpenReadAsync()
35-
=> (await this.blob.DownloadAsync()).Value.Content;
35+
{
36+
// Copy to a MemoryStream first because RetriableStreamImpl
37+
// doesn't support Position.
38+
Stream blobStream = (await this.blob.DownloadAsync()).Value.Content;
39+
var memoryStream = new ChunkedMemoryStream();
40+
41+
await blobStream.CopyToAsync(memoryStream);
42+
memoryStream.Seek(0, SeekOrigin.Begin);
43+
44+
return memoryStream;
45+
}
3646
}
3747
}

src/ImageSharp.Web/Caching/HexEncoder.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static class HexEncoder
2323
private static readonly char[] HexLutLo = Enumerable.Range(0, 256).Select(x => HexLutBase[x % 0x10]).ToArray();
2424

2525
/// <summary>
26-
/// Converts a <see cref="T:Span{byte}"/> to a hexidecimal formatted <see cref="string"/> padded to 2 digits.
26+
/// Converts a <see cref="ReadOnlySpan{Byte}"/> to a hexidecimal formatted <see cref="string"/> padded to 2 digits.
2727
/// </summary>
2828
/// <param name="bytes">The bytes.</param>
2929
/// <returns>The <see cref="string"/>.</returns>
@@ -35,20 +35,25 @@ public static unsafe string Encode(ReadOnlySpan<byte> bytes)
3535
return string.Create(bytes.Length * 2, (Ptr: (IntPtr)bytesPtr, bytes.Length), (chars, args) =>
3636
{
3737
var ros = new ReadOnlySpan<byte>((byte*)args.Ptr, args.Length);
38+
EncodeToUtf16(ros, chars);
39+
});
40+
}
41+
}
3842

39-
ref char charRef = ref MemoryMarshal.GetReference(chars);
40-
ref byte bytesRef = ref MemoryMarshal.GetReference(ros);
41-
ref char hiRef = ref MemoryMarshal.GetReference<char>(HexLutHi);
42-
ref char lowRef = ref MemoryMarshal.GetReference<char>(HexLutLo);
43+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
44+
private static void EncodeToUtf16(ReadOnlySpan<byte> bytes, Span<char> chars)
45+
{
46+
ref byte bytesRef = ref MemoryMarshal.GetReference(bytes);
47+
ref char charRef = ref MemoryMarshal.GetReference(chars);
48+
ref char hiRef = ref MemoryMarshal.GetReference<char>(HexLutHi);
49+
ref char lowRef = ref MemoryMarshal.GetReference<char>(HexLutLo);
4350

44-
int index = 0;
45-
for (int i = 0; i < ros.Length; i++)
46-
{
47-
byte byteIndex = Unsafe.Add(ref bytesRef, i);
48-
Unsafe.Add(ref charRef, index++) = Unsafe.Add(ref hiRef, byteIndex);
49-
Unsafe.Add(ref charRef, index++) = Unsafe.Add(ref lowRef, byteIndex);
50-
}
51-
});
51+
int index = 0;
52+
for (int i = 0; i < bytes.Length; i++)
53+
{
54+
byte byteIndex = Unsafe.Add(ref bytesRef, i);
55+
Unsafe.Add(ref charRef, index++) = Unsafe.Add(ref hiRef, byteIndex);
56+
Unsafe.Add(ref charRef, index++) = Unsafe.Add(ref lowRef, byteIndex);
5257
}
5358
}
5459
}

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public PhysicalFileSystemCache(
7070
Guard.NotNull(options, nameof(options));
7171
Guard.NotNullOrWhiteSpace(environment.WebRootPath, nameof(environment.WebRootPath));
7272

73+
// Allow configuration of the cache without having to register everything.
7374
this.cacheOptions = cacheOptions != null ? cacheOptions.Value : new PhysicalFileSystemCacheOptions();
7475
this.cacheRootPath = Path.Combine(environment.WebRootPath, this.cacheOptions.CacheFolder);
7576
if (!Directory.Exists(this.cacheRootPath))
@@ -160,14 +161,13 @@ private string ToImageFilePath(string path, in ImageCacheMetadata metaData)
160161
[MethodImpl(MethodImplOptions.AggressiveInlining)]
161162
internal static unsafe string ToFilePath(string key, int cachedNameLength)
162163
{
163-
const char separator = '/';
164-
165164
// Each key substring char + separator + key
166165
int length = (cachedNameLength * 2) + key.Length;
167166
fixed (char* keyPtr = key)
168167
{
169168
return string.Create(length, (Ptr: (IntPtr)keyPtr, key.Length), (chars, args) =>
170169
{
170+
const char separator = '/';
171171
var keySpan = new ReadOnlySpan<char>((char*)args.Ptr, args.Length);
172172
ref char keyRef = ref MemoryMarshal.GetReference(keySpan);
173173
ref char charRef = ref MemoryMarshal.GetReference(chars);

tests/ImageSharp.Web.Tests/ImageSharp.Web.Tests.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<RootNamespace>SixLabors.ImageSharp.Web.Tests</RootNamespace>
@@ -15,12 +15,12 @@
1515
</ItemGroup>
1616

1717
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
18-
<PackageReference Include="Microsoft.AspNetCore.TestHost"/>
18+
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
1919
</ItemGroup>
2020

2121
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
2222
<PackageReference Include="Microsoft.AspNetCore.Http" />
23-
<PackageReference Include="Microsoft.AspNetCore.TestHost"/>
23+
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
2424
</ItemGroup>
2525

2626
<ItemGroup>
@@ -29,6 +29,9 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32+
<None Update="SubFolder\imagesharp-logo.png">
33+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34+
</None>
3235
<None Update="xunit.runner.json">
3336
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3437
</None>

tests/ImageSharp.Web.Tests/ImageSharpTestServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static TestServer Create(Action<IApplicationBuilder> configureApp, Action
141141
IConfigurationRoot configuration = new ConfigurationBuilder()
142142
.AddInMemoryCollection(new[]
143143
{
144-
new KeyValuePair<string, string>("webroot", "../../../")
144+
new KeyValuePair<string, string>("webroot", string.Empty)
145145
}).Build();
146146

147147
IWebHostBuilder builder = new WebHostBuilder()

0 commit comments

Comments
 (0)