Skip to content

Commit

Permalink
Merge pull request #26 from JuliaComputing/tan/fixputblob
Browse files Browse the repository at this point in the history
avoid chunked transfers in putBlob when possible
  • Loading branch information
tanmaykm authored Dec 11, 2021
2 parents 4fd0112 + 592400d commit 0e2b55e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name = "Azure"
uuid = "34b51195-c7f2-5807-8107-6ca017e2682c"
keywords = ["azure", "cloud", "api", "julia"]
desc = "Julia interface to Azure APIs"
version = "0.4.0"
version = "0.4.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Swagger = "2d69052b-6a58-5cd9-a030-a48559c324ac"
XMLDict = "228000da-037f-5747-90a9-8195ccbf91a5"
Expand Down
1 change: 1 addition & 0 deletions src/StorageServices/StorageServices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using URIs
using MbedTLS
using Dates
using Base64
using Mmap

include("common.jl")
include("blob.jl")
Expand Down
29 changes: 28 additions & 1 deletion src/StorageServices/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ end

const valid_blob_types = ("BlockBlob", "PageBlob", "AppendBlob")

function check_mappable_file(io)
if isa(io, IOStream)
try
fsz = filesize(io)
data = Mmap.mmap(io, Vector{UInt8}, fsz)
return IOBuffer(data), fsz
catch
return io, nothing
end
end
return io, nothing
end

"""
Creates a new block, page, or append blob, or updates the content of an existing block blob.
Expand Down Expand Up @@ -164,8 +177,22 @@ function putBlob(ctx, subscription_id::String, resource_group_name::String, uri:
content_length = length(codeunits(block_blob_contents))
elseif isa(block_blob_contents, Vector{UInt8})
content_length = length(block_blob_contents)
elseif isa(block_blob_contents, IOBuffer)
content_length = block_blob_contents.size
else
wrapped_contents, content_length = check_mappable_file(block_blob_contents)
if content_length === nothing
error("content_length must be specified for blob contents of type $(typeof(block_blob_contents))")
else
block_blob_contents = wrapped_contents
end
end
elseif isa(block_blob_contents, IOStream)
wrapped_contents, wrapped_content_length = check_mappable_file(block_blob_contents)
if content_length !== wrapped_content_length
error("content_length must match the length of the stream")
else
error("content_length must be specified for blob contents of type $(typeof(block_blob_contents))")
block_blob_contents = wrapped_contents
end
end
end
Expand Down

2 comments on commit 0e2b55e

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/50357

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" 0e2b55e7602352d86bdf3579e547a74a9b5f44f8
git push origin v0.4.1

Please sign in to comment.