diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-03-08 21:39:33 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-03-08 21:39:33 -0700 |
| commit | 2e3f6ad3a97bc7fad349e63289695547f92c1f8b (patch) | |
| tree | 036cbe846cb6387a3a22cc0a19a1d6d770b061e7 /weed/util/http_util.go | |
| parent | 5ac6297c685a3bd6c9b8a3d0f2328dde01f7013a (diff) | |
| download | seaweedfs-2e3f6ad3a97bc7fad349e63289695547f92c1f8b.tar.xz seaweedfs-2e3f6ad3a97bc7fad349e63289695547f92c1f8b.zip | |
filer: remember content is gzipped or not
Diffstat (limited to 'weed/util/http_util.go')
| -rw-r--r-- | weed/util/http_util.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/weed/util/http_util.go b/weed/util/http_util.go index 833db910c..750516b92 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -189,11 +189,11 @@ func NormalizeUrl(url string) string { return "http://" + url } -func ReadUrl(fileUrl string, cipherKey []byte, isFullChunk bool, offset int64, size int, buf []byte) (int64, error) { +func ReadUrl(fileUrl string, cipherKey []byte, isGzipped bool, isFullChunk bool, offset int64, size int, buf []byte) (int64, error) { if cipherKey != nil { var n int - err := readEncryptedUrl(fileUrl, cipherKey, offset, size, func(data []byte) { + err := readEncryptedUrl(fileUrl, cipherKey, isGzipped, offset, size, func(data []byte) { n = copy(buf, data) }) return int64(n), err @@ -258,10 +258,10 @@ func ReadUrl(fileUrl string, cipherKey []byte, isFullChunk bool, offset int64, s return n, err } -func ReadUrlAsStream(fileUrl string, cipherKey []byte, isFullChunk bool, offset int64, size int, fn func(data []byte)) error { +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, offset, size, fn) + return readEncryptedUrl(fileUrl, cipherKey, isContentGzipped, offset, size, fn) } req, err := http.NewRequest("GET", fileUrl, nil) @@ -300,7 +300,7 @@ func ReadUrlAsStream(fileUrl string, cipherKey []byte, isFullChunk bool, offset } -func readEncryptedUrl(fileUrl string, cipherKey []byte, offset int64, size int, fn func(data []byte)) error { +func readEncryptedUrl(fileUrl string, cipherKey []byte, isContentGzipped 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) @@ -309,6 +309,12 @@ func readEncryptedUrl(fileUrl string, cipherKey []byte, offset int64, size int, if err != nil { return fmt.Errorf("decrypt %s: %v", fileUrl, err) } + if isContentGzipped { + decryptedData, err = UnGzipData(decryptedData) + if err != nil { + return fmt.Errorf("unzip decrypt %s: %v", fileUrl, err) + } + } if len(decryptedData) < int(offset)+size { return fmt.Errorf("read decrypted %s size %d [%d, %d)", fileUrl, len(decryptedData), offset, int(offset)+size) } |
