Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AzStorage"
uuid = "c6697862-1611-5eae-9ef8-48803c85c8d6"
version = "2.9.3"
version = "2.10.0"

[deps]
AbstractStorage = "14dbef02-f468-5f15-853e-5ec8dee7b899"
Expand Down
45 changes: 44 additions & 1 deletion src/AzStorage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,49 @@ Returns the size of the blob corresponding to `object::AzObject`
"""
Base.filesize(o::AzObject) = filesize(o.container, o.name)

"""
metadata(container, "blobname")

Returns a dictionary corresponding to the metadata of the blob "blobname" in `container::AzContainer`. The dictionary contains the following keys:

* "size": The size of the blob in bytes.
* "modified": The last modified date of the blob.
* "created": The creation date of the blob.
* "accessed": The last access date of the blob.
"""
function metadata(c::AzContainer, o::AbstractString)
r = @retry c.nretry HTTP.request(
"HEAD",
"https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/$(addprefix(c,o))",
[
"Authorization" => "Bearer $(token(c.session))",
"x-ms-version" => API_VERSION
],
retry = false,
verbose = c.verbose,
connect_timeout = c.connect_timeout,
readtimeout = c.read_timeout)

Dict(
"size" => parse(Int, HTTP.header(r, "Content-Length", "0")),
"modified" => tryparse(DateTime, HTTP.header(r, "Last-Modified", "not a date"), dateformat"e, dd u yyyy HH:MM:SS \G\M\T"),
"created" => tryparse(DateTime, HTTP.header(r, "x-ms-creation-time", "not a date"), dateformat"e, dd u yyyy HH:MM:SS \G\M\T"),
"accessed" => tryparse(DateTime, HTTP.header(r, "x-ms-last-access-time", "not a date"), dateformat"e, dd u yyyy HH:MM:SS \G\M\T")
)
end

"""
metadata(object::AzObject)

Returns a dictionary corresponding to the metadata of the blob corresponding to `object::AzObject`. The dictionary contains the following keys:

* "size": The size of the blob in bytes.
* "modified": The last modified date of the blob.
* "created": The creation date of the blob.
* "accessed": The last access date of the blob.
"""
metadata(o::AzObject) = metadata(o.container, o.name)

"""
rm(container, "blobname")

Expand Down Expand Up @@ -1540,6 +1583,6 @@ Returns the access tier for a blob `o::AzObject`.
"""
tier(o::AzObject) = tier(o.container, o.name)

export AzContainer, containers, readdlm, status, tier, tier!, writedlm
export AzContainer, containers, metadata, readdlm, status, tier, tier!, writedlm

end
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ end
rm(c)
end

@testset "Containers, metadata, prefix=$prefix" for prefix in ("", "prefix")
suffix = prefix == "" ? "-foo" : "-bar"
r = uuid4()
c = AzContainer("foo-$r-f$suffix", prefix=prefix, storageaccount=storageaccount, session=session)
c = robust_mkpath(c)

write(c, "bar", rand(UInt8,10))

m = metadata(c, "bar")
@test m["size"] == 10
@test isa(m["created"], DateTime)
@test isa(m["modified"], DateTime) || isa(m["modified"], Nothing)
@test isa(m["accessed"], DateTime) || isa(m["accessed"], Nothing)
end

@testset "Containers, bytes, nthreads=$nthreads, prefix=$prefix" for nthreads in (1, 2), prefix in ("","prefix")
suffix = prefix == "" ? "-foo" : "-bar"
r = uuid4()
Expand Down