|
107 | 107 |
|
108 | 108 | const valid_blob_types = ("BlockBlob", "PageBlob", "AppendBlob")
|
109 | 109 |
|
| 110 | +function check_mappable_file(io) |
| 111 | + if isa(io, IOStream) |
| 112 | + try |
| 113 | + fsz = filesize(io) |
| 114 | + data = Mmap.mmap(io, Vector{UInt8}, fsz) |
| 115 | + return IOBuffer(data), fsz |
| 116 | + catch |
| 117 | + return io, nothing |
| 118 | + end |
| 119 | + end |
| 120 | + return io, nothing |
| 121 | +end |
| 122 | + |
110 | 123 | """
|
111 | 124 | Creates a new block, page, or append blob, or updates the content of an existing block blob.
|
112 | 125 |
|
@@ -164,8 +177,22 @@ function putBlob(ctx, subscription_id::String, resource_group_name::String, uri:
|
164 | 177 | content_length = length(codeunits(block_blob_contents))
|
165 | 178 | elseif isa(block_blob_contents, Vector{UInt8})
|
166 | 179 | content_length = length(block_blob_contents)
|
| 180 | + elseif isa(block_blob_contents, IOBuffer) |
| 181 | + content_length = block_blob_contents.size |
| 182 | + else |
| 183 | + wrapped_contents, content_length = check_mappable_file(block_blob_contents) |
| 184 | + if content_length === nothing |
| 185 | + error("content_length must be specified for blob contents of type $(typeof(block_blob_contents))") |
| 186 | + else |
| 187 | + block_blob_contents = wrapped_contents |
| 188 | + end |
| 189 | + end |
| 190 | + elseif isa(block_blob_contents, IOStream) |
| 191 | + wrapped_contents, wrapped_content_length = check_mappable_file(block_blob_contents) |
| 192 | + if content_length !== wrapped_content_length |
| 193 | + error("content_length must match the length of the stream") |
167 | 194 | else
|
168 |
| - error("content_length must be specified for blob contents of type $(typeof(block_blob_contents))") |
| 195 | + block_blob_contents = wrapped_contents |
169 | 196 | end
|
170 | 197 | end
|
171 | 198 | end
|
|
0 commit comments