perf: multi-thread downloader, Content-Disposition (#4921)

general: enhance multi-thread downloader with cancelable context, immediately stop all stream processes when canceled;
feat(crypt): improve stream closing;
general: fix the bug of downloading files becomes previewing stream on modern browsers;

Co-authored-by: Sean He <866155+seanhe26@users.noreply.github.com>
Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
Sean
2023-08-04 15:29:54 +08:00
committed by GitHub
parent 861948bcf3
commit 15b7169df4
7 changed files with 58 additions and 34 deletions

View File

@ -164,3 +164,24 @@ func Retry(attempts int, sleep time.Duration, f func() error) (err error) {
}
return fmt.Errorf("after %d attempts, last error: %s", attempts, err)
}
type Closers struct {
closers []*io.Closer
}
func (c *Closers) Close() (err error) {
for _, closer := range c.closers {
if closer != nil {
_ = (*closer).Close()
}
}
return nil
}
func (c *Closers) Add(closer io.Closer) {
if closer != nil {
c.closers = append(c.closers, &closer)
}
}
func NewClosers() *Closers {
return &Closers{[]*io.Closer{}}
}