Table of Contents

Class PluginFiles

Namespace
Hi3Helper.Plugin.Core.Utility
Assembly
Hi3Helper.Plugin.Core.dll

Contains extensions related with Download operations and Copy-to routine.

public static class PluginFiles
Inheritance
PluginFiles
Inherited Members

Methods

CopyToAsyncProgress(Stream, Stream, FileReadProgressDelegate?, int, CancellationToken)

Performing copy operation from and to Stream asynchronously.

public static Task CopyToAsyncProgress(this Stream source, Stream destination, PluginFiles.FileReadProgressDelegate? progress, int bufferSize = 65536, CancellationToken token = default)

Parameters

source Stream

The source Stream to copy from.

destination Stream

The target Stream to copy into.

progress PluginFiles.FileReadProgressDelegate

A callback which reports the progress of the copy operation.

bufferSize int

The buffer size required to perform the copy operation.

token CancellationToken

A cancellation token for the async operation

Returns

Task

DownloadFilesAsync(HttpClient, string, Stream, FileReadProgressDelegate?, int, int, CancellationToken)

Perform an asynchronous download operation to a target Stream.

public static Task DownloadFilesAsync(this HttpClient client, string fileUrl, Stream outputStream, PluginFiles.FileReadProgressDelegate? downloadProgress, int bufferSize = 65536, int retryAttempt = 5, CancellationToken token = default)

Parameters

client HttpClient

An HTTP client to be used for downloading the file.

fileUrl string

The URL of the file.

outputStream Stream

The target Stream in which the data will be downloaded to.

downloadProgress PluginFiles.FileReadProgressDelegate

A callback which sends the progress of the download operation.

bufferSize int

How many bytes being used as a buffer for the download operation.

retryAttempt int

How many retry attempts are used in case of failure.

token CancellationToken

A cancellation token for the async operation

Returns

Task

Remarks

The first argument of PluginFiles.FileReadProgressDelegate delegate (read) passed by downloadProgress callback will send a negative number if a retry attempt is triggered.
This to avoid overflowed number if you're counting how many bytes are progressed using its read argument.