VcfDeserialize(FuncStream, AnsiFilter) Method

Deserializes a Stream of VCF data and selects the right Encoding automatically.

Definition

Namespace: FolkerKinzel.VCards
Assembly: FolkerKinzel.VCards (in FolkerKinzel.VCards.dll) Version: 8.0.1+a91cc3f0fd39aeb548e16006a60ca9dd10a304a2
C#
public static IReadOnlyList<VCard> Deserialize(
	Func<Stream?> factory,
	AnsiFilter filter
)

Parameters

factory  FuncStream
A function that returns a Stream or null.
filter  AnsiFilter
An AnsiFilter instance.

Return Value

IReadOnlyListVCard
A collection of parsed VCard objects.

Remarks

AnsiFilter only recognizes one Encoding per Stream. This means that if the Stream that factory returns contains VCF data with different Encodings, decoding errors may occur.

Any Streams that are used within the method will be closed when the method completes.

Example

C#
using FolkerKinzel.VCards;

namespace Examples;

public static class WebExample
{
    private const string URI =
        "https://raw.githubusercontent.com/FolkerKinzel/VCards/master/src/Examples/AnsiFilterExamples/German.vcf";

    private static readonly HttpClient _client = new();

    public static async Task AsyncExample()
    {
        using var cts = new CancellationTokenSource();

        IReadOnlyList<VCard> vc = await Vcf.DeserializeAsync(t => _client.GetStreamAsync(URI, t),
                                                     new AnsiFilter(),
                                                     cts.Token);
        Console.WriteLine(vc[0]);
    }

    public static void SynchronousExample()
    {
        using HttpResponseMessage response =
            _client.Send(new HttpRequestMessage(HttpMethod.Get, URI));

        IReadOnlyList<VCard> vc = Vcf.Deserialize(() => response.Content.ReadAsStream(),
                                          new AnsiFilter());
        Console.WriteLine(vc[0]);
    }
}

/*
Console Output:

Version: 2.1

DisplayNames: Sören Täve Nüßlebaum

NameViews:
    FamilyNames:     Nüßlebaum
    GivenNames:      Sören
    AdditionalNames: Täve

[Label: Mößlitz]
[CharSet: Windows-1252]
Addresses: Locality: Mößlitz
 */

Exceptions

ArgumentNullExceptionfactory or filter is null.
ArgumentExceptionThe Stream that factory returns doesn't support reading.
ObjectDisposedExceptionfactory returns a closed stream.
IOException The method could not read from the Stream that factory returns.

See Also