Skip to content

Commit

Permalink
Fix compatibility with RecyclableMemoryStream 3.x, drop compatibility…
Browse files Browse the repository at this point in the history
… with 1.x
  • Loading branch information
lilith committed Feb 6, 2024
1 parent 22ee5a2 commit ae68b97
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 99 deletions.
19 changes: 11 additions & 8 deletions src/Imageflow.AllPlatforms/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
},
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Transitive",
"resolved": "1.2.2",
"contentHash": "LA4RBTStohA0hAAs6oKchmIC5M5Mjd5MwfB7vbbl+312N5kXj8abTGOgwZy6ASJYLCiqiiK5kHS0hDGEgfkB8g=="
"resolved": "2.3.2",
"contentHash": "Oh1qXXFdJFcHozvb4H6XYLf2W0meZFuG0A+TfapFPj9z5fd4vxiARGEhAaLj/6XWQaMYIv4SH/9Q6H78Hw0E2Q==",
"dependencies": {
"System.Memory": "4.5.5"
}
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
Expand All @@ -60,8 +63,8 @@
},
"System.Memory": {
"type": "Transitive",
"resolved": "4.5.4",
"contentHash": "1MbJTHS1lZ4bS4FmsJjnuGJOu88ZzTT2rLvrhW7Ygic+pC0NWA+3hgAen0HRdsocuQXCkUTdFn9yHJJhsijDXw==",
"resolved": "4.5.5",
"contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==",
"dependencies": {
"System.Buffers": "4.5.1",
"System.Numerics.Vectors": "4.4.0",
Expand Down Expand Up @@ -113,7 +116,7 @@
"imageflow.net": {
"type": "Project",
"dependencies": {
"Microsoft.IO.RecyclableMemoryStream": "[1.2.*, 4.0.0)",
"Microsoft.IO.RecyclableMemoryStream": "[2.*, 4.0.0)",
"System.Text.Json": "[6.*, )"
}
}
Expand Down Expand Up @@ -151,8 +154,8 @@
},
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Transitive",
"resolved": "1.2.2",
"contentHash": "LA4RBTStohA0hAAs6oKchmIC5M5Mjd5MwfB7vbbl+312N5kXj8abTGOgwZy6ASJYLCiqiiK5kHS0hDGEgfkB8g=="
"resolved": "2.3.2",
"contentHash": "Oh1qXXFdJFcHozvb4H6XYLf2W0meZFuG0A+TfapFPj9z5fd4vxiARGEhAaLj/6XWQaMYIv4SH/9Q6H78Hw0E2Q=="
},
"System.Runtime.CompilerServices.Unsafe": {
"type": "Transitive",
Expand All @@ -179,7 +182,7 @@
"imageflow.net": {
"type": "Project",
"dependencies": {
"Microsoft.IO.RecyclableMemoryStream": "[1.2.*, 4.0.0)",
"Microsoft.IO.RecyclableMemoryStream": "[2.*, 4.0.0)",
"System.Text.Json": "[6.*, )"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Imageflow/Fluent/IBytesSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task<ArraySegment<byte>> GetBytesAsync(CancellationToken cancellati

if (_copy == null)
{
_copy = new RecyclableMemoryStream(Mgr, "StreamSource: IBytesSource", (int) length);
_copy = new RecyclableMemoryStream(Mgr,"StreamSource: IBytesSource", length);
await underlying.CopyToAsync(_copy,81920, cancellationToken);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Imageflow/Imageflow.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
</PropertyGroup>

<ItemGroup>

<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="$(RecyclableMemoryStreamVersion)" Condition="'$(RecyclableMemoryStreamVersion)' != ''" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="[1.2.*,4)" Condition="'$(RecyclableMemoryStreamVersion)' == ''" />
<PackageReference Include="System.Text.Json" Version="[6.*,)" Condition="'$(SystemTextJsonVersion)' == ''" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" Condition="'$(SystemTextJsonVersion)' != ''" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="[2.*,4)" />
<PackageReference Include="System.Text.Json" Version="[6.*,)"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.*" PrivateAssets="All" />
Expand Down
19 changes: 11 additions & 8 deletions src/Imageflow/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
".NETStandard,Version=v2.0": {
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Direct",
"requested": "[1.2.*, 4.0.0)",
"resolved": "1.2.2",
"contentHash": "LA4RBTStohA0hAAs6oKchmIC5M5Mjd5MwfB7vbbl+312N5kXj8abTGOgwZy6ASJYLCiqiiK5kHS0hDGEgfkB8g=="
"requested": "[2.*, 4.0.0)",
"resolved": "2.3.2",
"contentHash": "Oh1qXXFdJFcHozvb4H6XYLf2W0meZFuG0A+TfapFPj9z5fd4vxiARGEhAaLj/6XWQaMYIv4SH/9Q6H78Hw0E2Q==",
"dependencies": {
"System.Memory": "4.5.5"
}
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down Expand Up @@ -78,8 +81,8 @@
},
"System.Memory": {
"type": "Transitive",
"resolved": "4.5.4",
"contentHash": "1MbJTHS1lZ4bS4FmsJjnuGJOu88ZzTT2rLvrhW7Ygic+pC0NWA+3hgAen0HRdsocuQXCkUTdFn9yHJJhsijDXw==",
"resolved": "4.5.5",
"contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==",
"dependencies": {
"System.Buffers": "4.5.1",
"System.Numerics.Vectors": "4.4.0",
Expand Down Expand Up @@ -118,9 +121,9 @@
"net8.0": {
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Direct",
"requested": "[1.2.*, 4.0.0)",
"resolved": "1.2.2",
"contentHash": "LA4RBTStohA0hAAs6oKchmIC5M5Mjd5MwfB7vbbl+312N5kXj8abTGOgwZy6ASJYLCiqiiK5kHS0hDGEgfkB8g=="
"requested": "[2.*, 4.0.0)",
"resolved": "2.3.2",
"contentHash": "Oh1qXXFdJFcHozvb4H6XYLf2W0meZFuG0A+TfapFPj9z5fd4vxiARGEhAaLj/6XWQaMYIv4SH/9Q6H78Hw0E2Q=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
Expand Down
5 changes: 4 additions & 1 deletion tests/Imageflow.Test/Imageflow.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" />
<PackageReference Include="Newtonsoft.Json" Version="[13.0.3,14)" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />

<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="$(RecyclableMemoryStreamVersion)" Condition="'$(RecyclableMemoryStreamVersion)' != ''" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" Condition="'$(RecyclableMemoryStreamVersion)' == ''" />
<PackageReference Include="System.Text.Json" Version="[6.*,)" Condition="'$(SystemTextJsonVersion)' == ''" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" Condition="'$(SystemTextJsonVersion)' != ''" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Imageflow.AllPlatforms\Imageflow.AllPlatforms.csproj" />
Expand Down
29 changes: 29 additions & 0 deletions tests/Imageflow.Test/TestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,36 @@ public async Task TestBuildCommandStringWithWatermarks()
}

}
[Fact]
public async Task TestBuildCommandStringWithStreamsAndWatermarks()
{
var imageBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII=");
// var stream1 = new BufferedStream(new System.IO.MemoryStream(imageBytes));
// var stream2 = new BufferedStream(new System.IO.MemoryStream(imageBytes));
var stream1 = new BufferedStream(new MemoryStream(imageBytes));
Assert.Equal(137, stream1.ReadByte());
stream1.Seek(0, SeekOrigin.Begin);
var stream2 = new BufferedStream(new MemoryStream(imageBytes));
var stream3 = new BufferedStream(new MemoryStream(imageBytes));
using (var b = new ImageJob())
{
var watermarks = new List<InputWatermark>();
watermarks.Add(new InputWatermark(new StreamSource(stream1,true), new WatermarkOptions()));
watermarks.Add(new InputWatermark(new StreamSource(stream2,true), new WatermarkOptions().SetGravity(new ConstraintGravity(100,100))));

var r = await b.BuildCommandString(
new StreamSource(stream3,true),
new BytesDestination(),
"width=3&height=2&mode=stretch&scale=both&format=webp",watermarks).Finish().InProcessAsync();

Assert.Equal(3, r.First!.Width);
Assert.Equal("webp", r.First.PreferredExtension);
Assert.True(r.First.TryGetBytes().HasValue);
}

}


[Fact]
public async Task TestFilesystemJobPrep()
{
Expand Down
Loading

0 comments on commit ae68b97

Please sign in to comment.