diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-03-29 00:54:39 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-03-29 00:54:39 -0700 |
| commit | 057722bbf43ed51f518839b5ffbb52716aa81420 (patch) | |
| tree | 0aa541ebc99aa7fc51611cb294327314285844a7 /weed/util/http_util.go | |
| parent | ae2309dc58dbfb231fbf06ed7e16055a4fbc5df9 (diff) | |
| download | seaweedfs-057722bbf43ed51f518839b5ffbb52716aa81420.tar.xz seaweedfs-057722bbf43ed51f518839b5ffbb52716aa81420.zip | |
return part of the chunk if chunkview is not the full chunk
Diffstat (limited to 'weed/util/http_util.go')
| -rw-r--r-- | weed/util/http_util.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 750516b92..4b1a7b895 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -193,7 +193,7 @@ func ReadUrl(fileUrl string, cipherKey []byte, isGzipped bool, isFullChunk bool, if cipherKey != nil { var n int - err := readEncryptedUrl(fileUrl, cipherKey, isGzipped, offset, size, func(data []byte) { + err := readEncryptedUrl(fileUrl, cipherKey, isGzipped, isFullChunk, offset, size, func(data []byte) { n = copy(buf, data) }) return int64(n), err @@ -261,7 +261,7 @@ func ReadUrl(fileUrl string, cipherKey []byte, isGzipped bool, isFullChunk bool, func ReadUrlAsStream(fileUrl string, cipherKey []byte, isContentGzipped bool, isFullChunk bool, offset int64, size int, fn func(data []byte)) error { if cipherKey != nil { - return readEncryptedUrl(fileUrl, cipherKey, isContentGzipped, offset, size, fn) + return readEncryptedUrl(fileUrl, cipherKey, isContentGzipped, isFullChunk, offset, size, fn) } req, err := http.NewRequest("GET", fileUrl, nil) @@ -300,7 +300,7 @@ func ReadUrlAsStream(fileUrl string, cipherKey []byte, isContentGzipped bool, is } -func readEncryptedUrl(fileUrl string, cipherKey []byte, isContentGzipped bool, offset int64, size int, fn func(data []byte)) error { +func readEncryptedUrl(fileUrl string, cipherKey []byte, isContentGzipped bool, isFullChunk bool, offset int64, size int, fn func(data []byte)) error { encryptedData, err := Get(fileUrl) if err != nil { return fmt.Errorf("fetch %s: %v", fileUrl, err) @@ -318,7 +318,11 @@ func readEncryptedUrl(fileUrl string, cipherKey []byte, isContentGzipped bool, o if len(decryptedData) < int(offset)+size { return fmt.Errorf("read decrypted %s size %d [%d, %d)", fileUrl, len(decryptedData), offset, int(offset)+size) } - fn(decryptedData[int(offset) : int(offset)+size]) + if isFullChunk { + fn(decryptedData) + } else { + fn(decryptedData[int(offset) : int(offset)+size]) + } return nil } |
