-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 增加了当下载视频时,多线程分段下载的功能 1. 使用-m 参数启用多线程下载,线程数量由-n决定 2. 代码上是增加Save的可选版本MultiThreadSave版本。与进度条兼容。 3. MultiThreadSave的实现: 将文件分成指定的thread数量的part文件,每个part 文件记录着在整个文件中的偏移量,以及本part当前已下载的数据大小。恢复下载时,会同意所有part的信息,以支持继续下载。 当重新启动后,part数量与线程数量不同时,有以下两种情况: 1. 线程数量小于现存part数,则按线程池调度去完成所有part(使用信号量控制) 2. 线程数大于现存part数,则多于的线程不启用。 下载完成后,合并所有part,然后删除part文件(因此可能需要两倍大小的磁盘容量,回续可能优化) 线程调度方案也可能会优化,以尽量利用可能的线程 * [漏传了一个文件] 增加了当下载视频时,多线程分段下载的功能 1. 使用-m 参数启用多线程下载,线程数量由-n决定 2. 代码上是增加Save的可选版本MultiThreadSave版本。与进度条兼容。 3. MultiThreadSave的实现: 将文件分成指定的thread数量的part文件,每个part 文件记录着在整个文件中的偏移量,以及本part当前已下载的数据大小。恢复下载时,会同意所有part的信息,以支持继续下载。 当重新启动后,part数量与线程数量不同时,有以下两种情况: 1. 线程数量小于现存part数,则按线程池调度去完成所有part(使用信号量控制) 2. 线程数大于现存part数,则多于的线程不启用。 下载完成后,合并所有part,然后删除part文件(因此可能需要两倍大小的磁盘容量,回续可能优化) 线程调度方案也可能会优化,以尽量利用可能的线程 * 优化代码结构 * 1. 复原了Import包的位置 2. 规范了函数命名 3. 规范了注释 3. 优化了review中提到的代码,删掉了一些无用的变量 * 1. 修复合并后文件大小增加的bug * '合并后删掉part文件' * 1. 删除Signal * 1. 写文件时增加O_WRONLY flag 2. errors.new() 改为 fmt.Errorf() * 1. 修复恢复下载后文件数据不正常的bug(搞错了part下载完成时的Cur值) 2. 删掉了mustReadFile,合并到parseFilePartMeta 3. 仅在part文件为新创建时向文件写part meta。(因为文件打开模式为append,所以后续的writeFilePart Meta都会变成追加,倒是文件数据出错)。因此,part.Cur字段只在运行时有效。从part文件中读出的Cur并不代表实际的Cur。实际的Cur由part的文件大小 - part.Start来确定。 4. 增加对缺失part文件的检查。 当恢复下载检测到有part丢失时(part.End - lastEnd != 1),则认定part丢失,在中间插入新part。 5. 增加对合并时中断下载的检查。恢复下载时如果存在.download但是.download文件大小不等于实际文件大小,则删掉.download文件重新合并。 * 1. 补充对删除末尾的part的检查与恢复 * 1. 修复错误的引用dir方式 * 1. 修复恢复下载时对end的错误计算
- Loading branch information
1 parent
b0a84cf
commit 27a9baa
Showing
4 changed files
with
305 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27a9baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README.md file should be updated to document the use of the -m parameter.
27a9baa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm considering applying this feature to all types of videos, and I'll update the documentation at that time