Skip to content

Commit

Permalink
Put range from url (#7081)
Browse files Browse the repository at this point in the history
* [File]Upload Range From Url Sync

* [File]Upload Range From Url ASync

* Fix Pylint

* Fix Pylint
  • Loading branch information
xiafu-msft authored and annatisch committed Sep 9, 2019
1 parent ca006d9 commit 878aa73
Show file tree
Hide file tree
Showing 10 changed files with 4,465 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,57 @@ async def upload_range( # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace_async
async def upload_range_from_url(self, source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs # type: Any
):
# type: (str, int, int, int, **Any) -> Dict[str, Any]
'''
Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint.
:param int range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int range_end:
End of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param str source_url:
A URL of up to 2 KB in length that specifies an Azure file or blob.
The value should be URL-encoded as it would appear in a request URI.
If the source is in another account, the source must either be public
or must be authenticated via a shared access signature. If the source
is public, no authentication is required.
Examples:
https://myaccount.file.core.windows.net/myshare/mydir/myfile
https://otheraccount.file.core.windows.net/myshare/mydir/myfile?sastoken
:param int source_range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int timeout:
The timeout parameter is expressed in seconds.
'''

options = self._upload_range_from_url_options(
source_url=source_url,
range_start=range_start,
range_end=range_end,
source_range_start=source_range_start,
**kwargs
)
try:
return await self._client.file.upload_range_from_url(**options) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace_async
async def get_ranges( # type: ignore
self,
Expand Down
79 changes: 78 additions & 1 deletion sdk/storage/azure-storage-file/azure/storage/file/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

# pylint: disable=too-many-lines
import functools
from io import BytesIO
from typing import ( # pylint: disable=unused-import
Expand Down Expand Up @@ -753,6 +753,83 @@ def upload_range( # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@staticmethod
def _upload_range_from_url_options(source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs
):
# type: (...) -> Dict[str, Any]

if range_start is None or range_end is None or source_range_start is None:
raise ValueError("start_range must be specified")

# Format range
destination_range = 'bytes={0}-{1}'.format(range_start, range_end)
source_range = 'bytes={0}-{1}'.format(source_range_start, source_range_start + (range_end - range_start))

options = {
'copy_source': source_url,
'content_length': 0,
'source_range': source_range,
'range': destination_range,
'timeout': kwargs.pop('timeout', None),
'cls': return_response_headers}
options.update(kwargs)
return options

@distributed_trace
def upload_range_from_url(self, source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs # type: Any
):
# type: (str, int, int, int, **Any) -> Dict[str, Any]
'''
Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint.
:param int range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int range_end:
End of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param str source_url:
A URL of up to 2 KB in length that specifies an Azure file or blob.
The value should be URL-encoded as it would appear in a request URI.
If the source is in another account, the source must either be public
or must be authenticated via a shared access signature. If the source
is public, no authentication is required.
Examples:
https://myaccount.file.core.windows.net/myshare/mydir/myfile
https://otheraccount.file.core.windows.net/myshare/mydir/myfile?sastoken
:param int source_range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int timeout:
The timeout parameter is expressed in seconds.
'''

options = self._upload_range_from_url_options(
source_url=source_url,
range_start=range_start,
range_end=range_end,
source_range_start=source_range_start,
**kwargs
)
try:
return self._client.file.upload_range_from_url(**options) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace
def get_ranges( # type: ignore
self, start_range=None, # type: Optional[int]
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 878aa73

Please sign in to comment.