Skip to content

Utilities

TypNull edited this page May 8, 2024 · 1 revision

Summary

ChunkHandler Class

This class handles and merges the chunks of a file download.

Properties:

  • 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.

Methods:

  • 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:
  • Add: Type: void
    • This method adds a GetRequest that represents a chunk to the RequestContainer.
  • SetInfos: Type: void
    • This method sets the ContentLength for all chunks based on a specified GetRequest.
  • 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.

internal IOManager Class

This class provides utility methods for I/O operations.

Properties:

  • static InvalidFileNameChars: Type: char[]
    • This property represents an array of characters that are not allowed in file names.

Methods:

  • 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 returns false. It also returns false if the caller does not have the required permissions to access the input path.
  • 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 returns false.
  • 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 an ArgumentNullException when the environment variable for the home directory is not set on Unix platforms, and a SecurityException when the caller does not have the required permission to perform this operation.
  • 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 an ArgumentNullException when the home path is null or an empty string on Unix platforms, an ArgumentException when the path to the downloads folder is not of the correct format, an IOException when an I/O error occurs, and a SecurityException when the caller does not have the required permission to perform this operation.
  • 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.
Clone this wiki locally