-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(stream): http chucked upload issue #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
440dd0b
fix(stream): http chucked upload issue
TwoOnefour d6dd66c
fix(stream): use MmapThreshold
TwoOnefour 70b44fa
fix(stream): improve caching mechanism and handle size=0 case
j2rong4cn 1eec47f
fix bug
j2rong4cn 4ae1464
fix(buffer): optimize ReadAt method for improved performance
j2rong4cn 4ddb579
fix(upload): handle Content-Length and File-Size headers for better s…
j2rong4cn 3a82d01
fix(189pc): 移除重复限速
j2rong4cn a9f5cef
Merge remote-tracking branch 'upstream/main' into pr/TwoOnefour/1152
j2rong4cn 0fea41b
fix(upload): handle negative file size during streaming uploads
j2rong4cn cf4aec2
fix(upload): update header key from File-Size to X-File-Size for size…
j2rong4cn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package buffer | ||
|
|
||
| import ( | ||
| "errors" | ||
| "io" | ||
| "os" | ||
| ) | ||
|
|
||
| type PeekFile struct { | ||
| peek *Reader | ||
| file *os.File | ||
| offset int64 | ||
| size int64 | ||
| } | ||
|
|
||
| func (p *PeekFile) Read(b []byte) (n int, err error) { | ||
| n, err = p.ReadAt(b, p.offset) | ||
| if n > 0 { | ||
| p.offset += int64(n) | ||
| } | ||
| return n, err | ||
| } | ||
|
|
||
| func (p *PeekFile) ReadAt(b []byte, off int64) (n int, err error) { | ||
| if off < p.peek.Size() { | ||
| n, err = p.peek.ReadAt(b, off) | ||
| if err == nil || n == len(b) { | ||
| return n, nil | ||
| } | ||
| // EOF | ||
| } | ||
| var nn int | ||
| nn, err = p.file.ReadAt(b[n:], off+int64(n)-p.peek.Size()) | ||
| return n + nn, err | ||
| } | ||
|
|
||
| func (p *PeekFile) Seek(offset int64, whence int) (int64, error) { | ||
| switch whence { | ||
| case io.SeekStart: | ||
| case io.SeekCurrent: | ||
| if offset == 0 { | ||
| return p.offset, nil | ||
| } | ||
| offset = p.offset + offset | ||
| case io.SeekEnd: | ||
| offset = p.size + offset | ||
| default: | ||
| return 0, errors.New("Seek: invalid whence") | ||
| } | ||
|
|
||
| if offset < 0 || offset > p.size { | ||
| return 0, errors.New("Seek: invalid offset") | ||
| } | ||
| if offset <= p.peek.Size() { | ||
| _, err := p.peek.Seek(offset, io.SeekStart) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| _, err = p.file.Seek(0, io.SeekStart) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| } else { | ||
| _, err := p.peek.Seek(p.peek.Size(), io.SeekStart) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| _, err = p.file.Seek(offset-p.peek.Size(), io.SeekStart) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| } | ||
|
|
||
| p.offset = offset | ||
| return offset, nil | ||
| } | ||
|
|
||
| func (p *PeekFile) Size() int64 { | ||
| return p.size | ||
| } | ||
|
|
||
| func NewPeekFile(peek *Reader, file *os.File) (*PeekFile, error) { | ||
| stat, err := file.Stat() | ||
| if err == nil { | ||
| return &PeekFile{peek: peek, file: file, size: stat.Size() + peek.Size()}, nil | ||
| } | ||
| return nil, err | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.