@@ -19,6 +19,7 @@ abstract type AbstractBlobTree; end
19
19
# TODO : Should we have `istree` separate from `isdir`?
20
20
Base. isdir (x:: AbstractBlobTree ) = true
21
21
Base. isfile (tree:: AbstractBlobTree ) = false
22
+ Base. ispath (x:: AbstractBlobTree ) = true
22
23
23
24
# Number of children is not known without a (potentially high-latency) call to
24
25
# an external resource
@@ -125,27 +126,62 @@ Base.basename(file::Blob) = basename(file.path)
125
126
Base. abspath (file:: Blob ) = AbsPath (file. root, file. path)
126
127
Base. isdir (file:: Blob ) = false
127
128
Base. isfile (file:: Blob ) = true
129
+ Base. ispath (file:: Blob ) = true
128
130
129
131
function Base. show (io:: IO , :: MIME"text/plain" , file:: Blob )
130
- print (io, " 📄 " , file. path, " @ " , sys_abspath (file. root))
132
+ print (io, " 📄 " , file. path, " @ " , summary (file. root))
131
133
end
132
134
133
135
function AbstractTrees. printnode (io:: IO , file:: Blob )
134
136
print (io, " 📄 " , basename (file))
135
137
end
136
138
139
+ # Opening as Vector{UInt8} or as String uses IO interface
137
140
function Base. open (f:: Function , :: Type{Vector{UInt8}} , file:: Blob )
138
- open (IO, file) do io
141
+ open (IO, file. root, file . path ) do io
139
142
f (read (io)) # TODO : use Mmap?
140
143
end
141
144
end
142
145
143
146
function Base. open (f:: Function , :: Type{String} , file:: Blob )
144
- open (Vector{UInt8} , file) do buf
145
- f (String (buf ))
147
+ open (IO , file. root, file . path ) do io
148
+ f (read (io, String ))
146
149
end
147
150
end
148
151
152
+ # Default open-type for Blob is IO
153
+ Base. open (f:: Function , file:: Blob ; kws... ) = open (f, IO, file. root, file. path; kws... )
154
+
155
+ # Opening Blob as itself is trivial
156
+ function Base. open (f:: Function , :: Type{Blob} , file:: Blob )
157
+ f (file)
158
+ end
159
+
160
+ # open with other types T defers to the underlying storage system
161
+ function Base. open (f:: Function , :: Type{T} , file:: Blob ; kws... ) where {T}
162
+ open (f, T, file. root, file. path; kws... )
163
+ end
164
+
165
+ # Unscoped form of open
166
+ function Base. open (:: Type{T} , file:: Blob ; kws... ) where {T}
167
+ open (identity, T, file; kws... )
168
+ end
169
+
170
+ # read() is also supported for `Blob`s
171
+ Base. read (file:: Blob ) = read (file. root, file. path)
172
+ Base. read (file:: Blob , :: Type{T} ) where {T} = read (file. root, file. path, T)
173
+
174
+
175
+ # Support for opening AbsPath
176
+ #
177
+ # TODO : Put this elsewhere?
178
+ function Base. open (f:: Function , :: Type{T} , path:: AbsPath ; kws... ) where {T}
179
+ open (f, T, path. root, path. path; kws... )
180
+ end
181
+
182
+ Base. open (f:: Function , path:: AbsPath ; kws... ) = open (f, IO, path. root, path. path; kws... )
183
+
184
+
149
185
# -------------------------------------------------------------------------------
150
186
struct BlobTree{Root} <: AbstractBlobTree
151
187
root:: Root
@@ -165,7 +201,7 @@ function Base.show(io::IO, ::MIME"text/plain", tree::AbstractBlobTree)
165
201
# `children()` for all our trees. It'd be much easier if
166
202
# `AbstractTrees.has_children()` was used consistently upstream.
167
203
cs = children (tree)
168
- println (io, " 📂 Tree " , tree. path, " @ " , tree. root)
204
+ println (io, " 📂 Tree " , tree. path, " @ " , summary ( tree. root) )
169
205
for (i, c) in enumerate (cs)
170
206
print (io, " " , isdir (c) ? ' 📁' : ' 📄' , " " , basename (c))
171
207
if i != length (cs)
@@ -228,15 +264,8 @@ function children(tree::BlobTree)
228
264
[tree[c] for c in child_names]
229
265
end
230
266
231
- Base. open (f:: Function , file:: Blob ; kws... ) = open (f, file. root, file. path; kws... )
232
- Base. open (f:: Function , path:: AbsPath ; kws... ) = open (f, path. root, path. path; kws... )
233
-
234
267
function Base. open (f:: Function , :: Type{BlobTree} , tree:: BlobTree )
235
268
f (tree)
236
269
end
237
270
238
- function Base. open (f:: Function , :: Type{Blob} , file:: Blob )
239
- f (file)
240
- end
241
-
242
271
# Base.open(::Type{T}, file::Blob; kws...) where {T} = open(identity, T, file.root, file.path; kws...)
0 commit comments