Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
nuget package
Browse files Browse the repository at this point in the history
  • Loading branch information
FolkerKinzel committed Sep 30, 2023
1 parent cf6515a commit 806eb73
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![GitHub](https://img.shields.io/github/license/FolkerKinzel/Uris)](https://github.com/FolkerKinzel/Uris/blob/master/LICENSE)

## .NET library that supports working with URIs
[Project Reference and Release Notes](https://github.com/FolkerKinzel/Uris/releases/tag/v4.0.1)
[Project Reference and Release Notes](https://github.com/FolkerKinzel/Uris/releases/tag/v5.0.0)

The library supports:
- The "data" URL scheme ([RFC 2397](https://datatracker.ietf.org/doc/html/rfc2397)) which allows to embed data into a URI. The static `DataUrl` class allows
Expand All @@ -17,7 +17,7 @@ The library is designed to support performance and small heap allocation.
[Version History](https://github.com/FolkerKinzel/Uris/releases)

.
#### Example:
### Example:
Creating and parsing a "data" URL:
```csharp
using System.Diagnostics;
Expand Down
4 changes: 2 additions & 2 deletions src/FolkerKinzel.URIs/FolkerKinzel.URIs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageIcon>Logo.png</PackageIcon>
<PackageReadmeFile>NugetReadme.md</PackageReadmeFile>
<PackageVersion>5.0.0</PackageVersion>
<FileVersion>5.0.0.1</FileVersion>
<FileVersion>5.0.0.6</FileVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<Description>.NET library that supports working with URIs</Description>
<PackageTags>URI URL C# .NET</PackageTags>
Expand Down Expand Up @@ -73,7 +73,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FolkerKinzel.MimeTypes" Version="5.0.0" />
<PackageReference Include="FolkerKinzel.MimeTypes" Version="5.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
35 changes: 22 additions & 13 deletions src/FolkerKinzel.URIs/Properties/Res.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/FolkerKinzel.URIs/Properties/Res.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="EmptyStruct" xml:space="preserve">
<value>An empty struct is not allowed.</value>
</data>
<data name="InvalidDataUrl" xml:space="preserve">
<value>{0} is not a valid "data" URL.</value>
</data>
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions src/FolkerKinzel.Uris.Tests/DataUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ public void FromBytesTest8()
Assert.AreEqual("application/octet-stream", info.MimeType.ToString());
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void FromBytesTest9() => _ = DataUrl.FromBytes(new byte[] { 1, 2, 3 }, new MimeTypeInfo());


[TestMethod]
public void FromFileTest1()
Expand Down Expand Up @@ -374,6 +378,10 @@ public void FromFileTest11()
Assert.AreEqual("image/jpeg", info.MimeType.ToString());
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void FromFileTest12() => _ = DataUrl.FromFile(TestFiles.FolkerPng, new MimeTypeInfo());


[TestMethod]
public void FromTextOnNull()
Expand Down
27 changes: 22 additions & 5 deletions src/FolkerKinzel.Uris/DataUrl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel;
using FolkerKinzel.MimeTypes;
using FolkerKinzel.Uris.Intls;
using FolkerKinzel.Uris.Properties;

namespace FolkerKinzel.Uris;

Expand Down Expand Up @@ -112,7 +113,7 @@ public static string FromBytes(byte[]? bytes,
/// <param name="dataEncoding">The encoding to use to embed the <paramref name="bytes"/>.</param>
///
/// <returns>A "data" URL, into which the binary data provided by the parameter <paramref name="bytes"/> is embedded.</returns>
/// <exception cref="ArgumentNullException"><paramref name="mimeType"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="mimeType"/> is an empty struct.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string FromBytes(byte[]? bytes,
in MimeTypeInfo mimeType,
Expand Down Expand Up @@ -185,7 +186,12 @@ public static string FromFile(string filePath,
/// <returns>A "data" URL into which the content of the file provided by the parameter <paramref name="filePath"/> is embedded.</returns>
///
///<exception cref="ArgumentNullException"><paramref name="filePath"/> or <paramref name="mimeType"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="filePath"/> is not a valid file path.</exception>
/// <exception cref="ArgumentException">
/// <para>
/// <paramref name="filePath"/> is not a valid file path
/// </para>
/// <para>- or -</para>
/// <para><paramref name="mimeType"/> is an empty struct.</para></exception>
/// <exception cref="IOException">I/O error.</exception>
public static string FromFile(string filePath,
in MimeTypeInfo mimeType,
Expand Down Expand Up @@ -304,13 +310,16 @@ public static StringBuilder AppendEmbeddedBytesTo(StringBuilder builder,
/// <returns>A reference to <paramref name="builder"/>.</returns>
///
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="mimeType"/> is an empty struct.</exception>
public static StringBuilder AppendEmbeddedBytesTo(StringBuilder builder,
byte[]? bytes,
in MimeTypeInfo mimeType,
DataEncoding dataEncoding = DataEncoding.Base64)
=> builder is null
? throw new ArgumentNullException(nameof(builder))
: builder.AppendEmbeddedBytesInternal(bytes, in mimeType, dataEncoding);
: mimeType.IsEmpty
? throw new ArgumentException(Res.EmptyStruct, nameof(mimeType))
: builder.AppendEmbeddedBytesInternal(bytes, in mimeType, dataEncoding);


/// <summary>
Expand Down Expand Up @@ -338,6 +347,7 @@ public static StringBuilder AppendEmbeddedFileTo(StringBuilder builder,
? AppendEmbeddedFileTo(builder, filePath, in mimeTypeInfo, dataEncoding)
: AppendEmbeddedFileTo(builder, filePath, (string?)null, dataEncoding);


/// <summary>
/// Appends the content of a file as "data" URL (RFC 2397) to the end of a <see cref="StringBuilder"/>.
/// </summary>
Expand Down Expand Up @@ -380,7 +390,12 @@ public static StringBuilder AppendEmbeddedFileTo(this StringBuilder builder,
///
/// <exception cref="ArgumentNullException"><paramref name="builder"/> or <paramref name="filePath"/>,
/// is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="filePath"/> is not a valid file path.</exception>
/// <exception cref="ArgumentException">
/// <para>
/// <paramref name="filePath"/> is not a valid file path
/// </para>
/// <para>- or -</para>
/// <para><paramref name="mimeType"/> is an empty struct.</para></exception>
/// <exception cref="IOException">I/O error.</exception>
public static StringBuilder AppendEmbeddedFileTo(StringBuilder builder,
string filePath,
Expand All @@ -390,7 +405,9 @@ public static StringBuilder AppendEmbeddedFileTo(StringBuilder builder,
? throw new ArgumentNullException(nameof(builder))
: filePath is null
? throw new ArgumentNullException(nameof(filePath))
: builder.AppendFileContentInternal(filePath, in mimeType, dataEncoding);
: mimeType.IsEmpty
? throw new ArgumentException(Res.EmptyStruct, nameof(mimeType))
: builder.AppendFileContentInternal(filePath, in mimeType, dataEncoding);


/// <summary>
Expand Down

0 comments on commit 806eb73

Please sign in to comment.