diff --git a/docs/src/example.md b/docs/src/example.md index e4e35a7..2805301 100644 --- a/docs/src/example.md +++ b/docs/src/example.md @@ -81,6 +81,9 @@ cp("mylocalfile.bin", io) io2 = open(AzContainer("foo"; storageaccount="mystorageaccount", session), "mycopyblob.bin") cp(io, io2) +# get the container (similar to getting the root path of a POSIX filename) +dirname(io) + # remove the blob rm(io) ``` diff --git a/src/AzStorage.jl b/src/AzStorage.jl index c3c1097..f12b835 100644 --- a/src/AzStorage.jl +++ b/src/AzStorage.jl @@ -102,6 +102,13 @@ write(io, rand(10)) """ Base.joinpath(container::AzContainer, name...) = open(container, join(name, '/'), false) +""" + dirname(object::AzObject) -> AzContainer + +returns the container/prefix of the `object::AzObject`. +""" +Base.dirname(object::AzObject) = object.container + """ open(object::AzObject[, mode="w+"]) -> object diff --git a/test/runtests.jl b/test/runtests.jl index 573ff58..f34c3ee 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -396,6 +396,19 @@ end c = AzContainer(""; storageaccount="", session=session, nthreads=2, nretry=10) io = joinpath(c, "bar", "baz") @test isfile(io) == false + rm(c) +end + +@testset "Object, dirname" begin + r = uuid4() + c = AzContainer("foo-$r-k", storageaccount=storageaccount, session=session, nthreads=2, nretry=10) + io = robust_joinpath(c, "bar", "baz") + _c = dirname(io) + @test isa(_c, AzContainer) + @test _c.storageaccount == c.storageaccount + @test _c.containername == c.containername + @test _c.prefix == c.prefix + rm(c) end @testset "Object, open" begin