/// <summary> /// 增量下载文件 /// </summary> /// <param name="storageNode">GetStorageNode方法返回的存储节点</param> /// <param name="fileName">文件名</param> /// <param name="offset">从文件起始点的偏移量</param> /// <param name="length">要读取的字节数</param> /// <returns>文件内容</returns> public static byte[] DownloadFile(StorageNode storageNode, string fileName, long offset, long length) { fileName = GetFileName(storageNode.GroupName, fileName); using (var storageReqeust = DOWNLOAD_FILE.CreateRequest(storageNode.EndPoint, offset, length, storageNode.GroupName, fileName)) { var storageResponse = new DOWNLOAD_FILE.Response(storageReqeust.GetStorageResponse()); return(storageResponse.Content); } }
/// <summary> /// 异步下载 /// </summary> /// <param name="storageNode"></param> /// <param name="fileName"></param> /// <returns></returns> public static async Task <byte[]> DownloadFileAsync(StorageNode storageNode, string fileName) { fileName = GetFileName(storageNode.GroupName, fileName); using (var storageReqeust = DOWNLOAD_FILE.CreateRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName)) { Task <byte[]> task = null; // storageReqeust.ReadBytesAsync(); await task; return(task.Result); } }
/// <summary> /// 下载文件 /// </summary> /// <param name="storageNode">GetStorageNode方法返回的存储节点</param> /// <param name="fileName">文件名</param> /// <exception cref="System.Exception">读取网络资源异常</exception> /// <returns>文件内容</returns> public static byte[] DownloadFile(StorageNode storageNode, string fileName) { fileName = GetFileName(storageNode.GroupName, fileName); using (var storageReqeust = DOWNLOAD_FILE.CreateRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName)) { // 同步下载 var storageResponse = new DOWNLOAD_FILE.Response(storageReqeust.GetStorageResponse()); if (storageResponse.Content == null) { throw new System.Exception(storageReqeust.Message); } return(storageResponse.Content); } }