MCPcopy Create free account
hub / github.com/apache/cloudberry / checkCompressionType

Method checkCompressionType

gpcontrib/gpcloud/src/s3interface.cpp:369–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369S3CompressionType S3InterfaceService::checkCompressionType(const S3Url &s3Url) {
370 string ext = s3Url.getExtension();
371 if (ext == ".deflate") {
372 return S3_COMPRESSION_DEFLATE;
373 }
374
375 HTTPHeaders headers;
376
377 char rangeBuf[S3_RANGE_HEADER_STRING_LEN] = {0};
378 snprintf(rangeBuf, sizeof(rangeBuf), "bytes=%d-%d", 0, S3_MAGIC_BYTES_NUM - 1);
379
380 headers.Add(HOST, s3Url.getHostForCurl());
381 headers.Add(RANGE, rangeBuf);
382 headers.Add(X_AMZ_CONTENT_SHA256,
383 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); // sha256hex
384 // of empty
385 // string
386
387 SignRequestV4("GET", &headers, s3Url.getRegion(), s3Url.getPathForCurl(), "",
388 this->params.getCred());
389
390 Response resp = this->getResponseWithRetries(s3Url.getFullUrlForCurl(), headers);
391 if (resp.getStatus() == RESPONSE_OK) {
392 S3VectorUInt8 &responseData = resp.getRawData();
393 if (responseData.size() < S3_MAGIC_BYTES_NUM) {
394 return S3_COMPRESSION_PLAIN;
395 }
396
397 S3_CHECK_OR_DIE(responseData.size() == S3_MAGIC_BYTES_NUM, S3PartialResponseError,
398 S3_MAGIC_BYTES_NUM, responseData.size());
399
400 if ((responseData[0] == 0x1f) && (responseData[1] == 0x8b)) {
401 return S3_COMPRESSION_GZIP;
402 }
403 } else if (resp.getStatus() == RESPONSE_ERROR) {
404 S3MessageParser s3msg(resp);
405 S3_DIE(S3LogicError, s3msg.getCode(), s3msg.getMessage());
406 } else {
407 S3_DIE(S3RuntimeError, "unexpected response status");
408 }
409
410 return S3_COMPRESSION_PLAIN;
411}
412
413bool S3InterfaceService::checkKeyExistence(const S3Url &s3Url) {
414 HTTPHeaders headers;

Callers 2

TEST_FFunction · 0.80
openMethod · 0.80

Calls 12

SignRequestV4Function · 0.85
getExtensionMethod · 0.80
getHostForCurlMethod · 0.80
getPathForCurlMethod · 0.80
getFullUrlForCurlMethod · 0.80
getStatusMethod · 0.80
AddMethod · 0.45
getRawDataMethod · 0.45
sizeMethod · 0.45
getCodeMethod · 0.45
getMessageMethod · 0.45

Tested by 1

TEST_FFunction · 0.64