Skip to content

Commit 6eba05e

Browse files
committed
add metadata method
1 parent a1b23c1 commit 6eba05e

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AzStorage"
22
uuid = "c6697862-1611-5eae-9ef8-48803c85c8d6"
3-
version = "2.9.3"
3+
version = "2.10.0"
44

55
[deps]
66
AbstractStorage = "14dbef02-f468-5f15-853e-5ec8dee7b899"

src/AzStorage.jl

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,49 @@ Returns the size of the blob corresponding to `object::AzObject`
13351335
"""
13361336
Base.filesize(o::AzObject) = filesize(o.container, o.name)
13371337

1338+
"""
1339+
metadata(container, "blobname")
1340+
1341+
Returns a dictionary corresponding to the metadata of the blob "blobname" in `container::AzContainer`. The dictionary contains the following keys:
1342+
1343+
* "size": The size of the blob in bytes.
1344+
* "modified": The last modified date of the blob.
1345+
* "created": The creation date of the blob.
1346+
* "accessed": The last access date of the blob.
1347+
"""
1348+
function metadata(c::AzContainer, o::AbstractString)
1349+
r = @retry c.nretry HTTP.request(
1350+
"HEAD",
1351+
"https://$(c.storageaccount).blob.core.windows.net/$(c.containername)/$(addprefix(c,o))",
1352+
[
1353+
"Authorization" => "Bearer $(token(c.session))",
1354+
"x-ms-version" => API_VERSION
1355+
],
1356+
retry = false,
1357+
verbose = c.verbose,
1358+
connect_timeout = c.connect_timeout,
1359+
readtimeout = c.read_timeout)
1360+
1361+
Dict(
1362+
"size" => parse(Int, HTTP.header(r, "Content-Length", "0")),
1363+
"modified" => tryparse(DateTime, HTTP.header(r, "Last-Modified", "not a date"), dateformat"e, dd u yyyy HH:MM:SS \G\M\T"),
1364+
"created" => tryparse(DateTime, HTTP.header(r, "x-ms-creation-time", "not a date"), dateformat"e, dd u yyyy HH:MM:SS \G\M\T"),
1365+
"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")
1366+
)
1367+
end
1368+
1369+
"""
1370+
metadata(object::AzObject)
1371+
1372+
Returns a dictionary corresponding to the metadata of the blob corresponding to `object::AzObject`. The dictionary contains the following keys:
1373+
1374+
* "size": The size of the blob in bytes.
1375+
* "modified": The last modified date of the blob.
1376+
* "created": The creation date of the blob.
1377+
* "accessed": The last access date of the blob.
1378+
"""
1379+
metadata(o::AzObject) = metadata(o.container, o.name)
1380+
13381381
"""
13391382
rm(container, "blobname")
13401383
@@ -1540,6 +1583,6 @@ Returns the access tier for a blob `o::AzObject`.
15401583
"""
15411584
tier(o::AzObject) = tier(o.container, o.name)
15421585

1543-
export AzContainer, containers, readdlm, status, tier, tier!, writedlm
1586+
export AzContainer, containers, metadata, readdlm, status, tier, tier!, writedlm
15441587

15451588
end

test/runtests.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ end
220220
rm(c)
221221
end
222222

223+
@testset "Containers, metadata, prefix=$prefix" for prefix in ("", "prefix")
224+
suffix = prefix == "" ? "-foo" : "-bar"
225+
r = uuid4()
226+
c = AzContainer("foo-$r-f$suffix", prefix=prefix, storageaccount=storageaccount, session=session)
227+
c = robust_mkpath(c)
228+
229+
write(c, "bar", rand(UInt8,10))
230+
231+
m = metadata(c, "bar")
232+
@test m["size"] == 10
233+
@test isa(m["created"], DateTime)
234+
@test isa(m["modified"], DateTime) || isa(m["modified"], Nothing)
235+
@test isa(m["accessed"], DateTime) || isa(m["accessed"], Nothing)
236+
end
237+
223238
@testset "Containers, bytes, nthreads=$nthreads, prefix=$prefix" for nthreads in (1, 2), prefix in ("","prefix")
224239
suffix = prefix == "" ? "-foo" : "-bar"
225240
r = uuid4()

0 commit comments

Comments
 (0)