-
Notifications
You must be signed in to change notification settings - Fork 1
Utilities
TypNull edited this page May 8, 2024
·
1 revision
This class handles and merges the chunks of a file download.
-
RequestContainer: Type:
ProgressableContainer<GetRequest>
- This property is a container for all chunks of the file download.
-
BytesWritten: Type:
long
- This property represents the number of bytes that have been written to the temporary file.
-
BytesDownloaded: Type:
long
- This property represents the total number of bytes that have been written to all chunk files.
-
Requests: Type:
GetRequest[]
- This property gets all the requests that are in the
RequestContainer
.
- This property gets all the requests that are in the
-
StartMergeTo: Type:
Task<bool>
- This method merges all chunked parts of a file into one large file. The path to the destination file is passed as a parameter. The task result contains a boolean value indicating whether all chunks were successfully merged.
-
DeleteChunkFiles: Type:
Task
- This method deletes the files associated with the requests up to the given count. The task represents the asynchronous operation.
Here is the continuation of the documentation for the
ChunkHandler
class:
- This method deletes the files associated with the requests up to the given count. The task represents the asynchronous operation.
Here is the continuation of the documentation for the
-
Add: Type:
void
- This method adds a
GetRequest
that represents a chunk to theRequestContainer
.
- This method adds a
-
SetInfos: Type:
void
- This method sets the
ContentLength
for all chunks based on a specifiedGetRequest
.
- This method sets the
-
TrySetBytesAsync: Type:
Task<bool>
- This method attempts to set the number of written bytes if no bytes have been downloaded yet. The task result contains a boolean value indicating whether the operation was successful.
-
private
MergeChunks: Type:Task
- This method merges the chunks of data into the specified destination. The destination file path where the chunks will be merged is passed as a parameter. Here is the continuation of the documentation for the
-
private
WriteChunkToDestination: Type:Task
- This method writes a chunk of data from the specified path to the output stream.
-
private
CalculatePartialContentLength: Type:(int count, bool rest)
- This method calculates the partial content length based on the number of bytes. It returns a tuple containing the count of requests and the remaining bytes.
-
private
ProcessRequestsCompletion: Type:void
- This method processes the requests up to the given count.
-
private
PauseAndReplaceRequest: Type:void
- This method pauses and replaces the request at the given index with a new request.
This class provides utility methods for I/O operations.
-
static
InvalidFileNameChars: Type:char[]
- This property represents an array of characters that are not allowed in file names.
-
static
BytesToMegabytes: Type:double
- This method converts bytes to megabytes. For example, if the input is 1,048,576 bytes, the return value is 1.
-
static
RemoveInvalidFileNameChars: Type:string
- This method removes all invalid characters from a file name and returns the cleaned file name.
-
static
IsValidPath: Type:bool
- This method determines whether a path is valid. It returns
true
if the input path is a valid path; otherwise, it returnsfalse
. It also returnsfalse
if the caller does not have the required permissions to access the input path.
- This method determines whether a path is valid. It returns
-
static
TryGetFullPath: Type:bool
- This method tries to get the absolute path for the specified path string. It returns
true
if the input path was converted to an absolute path successfully; otherwise, it returnsfalse
.
- This method tries to get the absolute path for the specified path string. It returns
-
static
GetHomePath: Type:Nullable<string>
- This method gets the home directory path. It returns the path to the home directory, or
null
if the path cannot be determined. It throws anArgumentNullException
when the environment variable for the home directory is not set on Unix platforms, and aSecurityException
when the caller does not have the required permission to perform this operation.
- This method gets the home directory path. It returns the path to the home directory, or
-
static
GetDownloadFolderPath: Type:Nullable<string>
- This method gets the path to the downloads folder. It returns the path to the downloads folder, or
null
if the path cannot be determined. It throws anArgumentNullException
when the home path is null or an empty string on Unix platforms, anArgumentException
when the path to the downloads folder is not of the correct format, anIOException
when an I/O error occurs, and aSecurityException
when the caller does not have the required permission to perform this operation.
- This method gets the path to the downloads folder. It returns the path to the downloads folder, or
-
static
Move: Type:void
- This method moves a file to a new location, overwriting the existing file if it exists.
-
static
Create: Type:void
- This method creates a new file or overwrites an existing file.