Skip to content

Commit 5ff2eb2

Browse files
committed
add dirname method for AzObject
1 parent 2d326ff commit 5ff2eb2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

docs/src/example.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ cp("mylocalfile.bin", io)
8181
io2 = open(AzContainer("foo"; storageaccount="mystorageaccount", session), "mycopyblob.bin")
8282
cp(io, io2)
8383

84+
# get the container (similar to getting the root path of a POSIX filename)
85+
dirname(io)
86+
8487
# remove the blob
8588
rm(io)
8689
```

src/AzStorage.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ write(io, rand(10))
102102
"""
103103
Base.joinpath(container::AzContainer, name...) = open(container, join(name, '/'), false)
104104

105+
"""
106+
dirname(object::AzObject) -> AzContainer
107+
108+
returns the container/prefix of the `object::AzObject`.
109+
"""
110+
Base.dirname(object::AzObject) = object.container
111+
105112
"""
106113
open(object::AzObject[, mode="w+"]) -> object
107114

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,19 @@ end
396396
c = AzContainer(""; storageaccount="", session=session, nthreads=2, nretry=10)
397397
io = joinpath(c, "bar", "baz")
398398
@test isfile(io) == false
399+
rm(c)
400+
end
401+
402+
@testset "Object, dirname" begin
403+
r = uuid4()
404+
c = AzContainer("foo-$r-k", storageaccount=storageaccount, session=session, nthreads=2, nretry=10)
405+
io = robust_joinpath(c, "bar", "baz")
406+
_c = dirname(io)
407+
@test isa(_c, AzContainer)
408+
@test _c.storageaccount == c.storageaccount
409+
@test _c.containername == c.containername
410+
@test _c.prefix == c.prefix
411+
rm(c)
399412
end
400413

401414
@testset "Object, open" begin

0 commit comments

Comments
 (0)