-
Notifications
You must be signed in to change notification settings - Fork 10
Adding example for Get range #62
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
Open
ashap-spectra
wants to merge
4
commits into
master
Choose a base branch
from
AG/Range-Example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import tempfile | ||
|
||
from ds3 import ds3, ds3Helpers,ds3network | ||
from ds3.ds3 import * | ||
import time | ||
|
||
|
||
# This example retrieves specified bytes=53687091100-53687091115 in the file in a specific bucket. | ||
# The output will be written to tempname file. | ||
|
||
|
||
client = ds3.Client("<host>", ds3.Credentials("<access id", "<secret key>")) | ||
|
||
# create a dictionary to map bucket names to object names | ||
object_dict={} | ||
helper = ds3Helpers.Helper(client=client) | ||
|
||
|
||
|
||
file_path = os.path.join(os.path.dirname(str(__file__)), "<file-name>") | ||
bucketName = "<bucket-name>" | ||
fileName = "<file-name>" | ||
fd, tempname = tempfile.mkstemp() | ||
print (tempname) | ||
f = open(tempname, "wb") | ||
bucketObjects = client.get_service(ds3.GetServiceRequest()) | ||
print(bucketObjects) | ||
|
||
# Create a GetObjectRequest and set the range header to retrieve only those bytes. | ||
# You can specify multiple ranges by separating them with commas. Example: | ||
# req.headers['Range'] = 'bytes=0-1,3-4' | ||
req = ds3.GetObjectRequest(bucketName, fileName, f) | ||
req.headers['Range'] = 'bytes=53687091100-53687091115' | ||
start_time = time.time() | ||
getObjectResult = client.get_object(request= req) | ||
|
||
|
||
f.close() | ||
os.close(fd) | ||
|
||
print(getObjectResult.response.status) | ||
end_time = time.time() | ||
elapsed_time_total = end_time - start_time | ||
print(f"Total elapsed time: {elapsed_time_total} seconds") |
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,45 @@ | ||
import os | ||
import tempfile | ||
from ds3 import ds3 | ||
import time | ||
|
||
|
||
# This example retrieves specified bytes=53687091100-53687091115 in the file in a specific bucket. | ||
# The output will be written to tempname file. | ||
|
||
|
||
client = ds3.createClientFromEnv() | ||
|
||
#Change the following values to match your environment | ||
# Part size is the size of each upload part in bytes | ||
PART_SIZE = 5 * 1024 * 1024 | ||
BUCKET_NAME = "books" | ||
OBJECT_KEY = "beowulf.txt" | ||
FILE_PATH = "beowulf.txt" | ||
|
||
#First step is to intiate the multipart upload. This will return uploadId which is used in the next request. | ||
req = ds3.InitiateMultiPartUploadRequest(BUCKET_NAME, OBJECT_KEY) | ||
res = client.initiate_multi_part_upload(req) | ||
uploadId = res.result['UploadId'] | ||
file_size = os.path.getsize(FILE_PATH) | ||
parts = [] | ||
|
||
with open(FILE_PATH, "rb") as file: | ||
part_number = 1 | ||
while True: | ||
chunk = file.read(PART_SIZE) | ||
if not chunk: | ||
break | ||
|
||
req = ds3.PutMultiPartUploadPartRequest( | ||
bucket_name=BUCKET_NAME, | ||
object_name=OBJECT_KEY, | ||
part_number=part_number, | ||
upload_id=uploadId, | ||
request_payload=chunk | ||
) | ||
|
||
multi_res = client.put_multi_part_upload_part(req) | ||
part_number += 1 | ||
|
||
print (res.result) |
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.