diff --git a/Project.toml b/Project.toml index 7ffbf3b..79f404f 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ 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" @@ -10,6 +10,7 @@ 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" diff --git a/src/StorageServices/StorageServices.jl b/src/StorageServices/StorageServices.jl index ab7c9f4..b997ce4 100644 --- a/src/StorageServices/StorageServices.jl +++ b/src/StorageServices/StorageServices.jl @@ -8,6 +8,7 @@ using URIs using MbedTLS using Dates using Base64 +using Mmap include("common.jl") include("blob.jl") diff --git a/src/StorageServices/blob.jl b/src/StorageServices/blob.jl index f389cb3..0eb5288 100644 --- a/src/StorageServices/blob.jl +++ b/src/StorageServices/blob.jl @@ -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. @@ -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