Skip to content

Commit fa8d51b

Browse files
committed
Clarify docs surrounding open()
Updated to be more explicit the role of the unscoped vs scoped forms of open.
1 parent 5727f82 commit fa8d51b

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

docs/dev.jl

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
using LiveServer
2+
servedocs(doc_env=true, foldername=@__DIR__)

docs/src/tutorial.md

+39-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ end
1010
DocTestFilters = [
1111
r"(?<=Project: \[).*$",
1212
r"path =.*",
13-
r"@.*"
13+
r"@.*",
14+
r"(?<=IOStream\().*",
1415
]
1516
```
1617

@@ -85,17 +86,42 @@ path = ".../DataSets/docs/src/data/file.txt"
8586

8687
## Loading Data
8788

88-
To load data, call the `open()` function on the `DataSet` and pass the desired
89-
Julia type which will be returned. For example, to read the dataset named
90-
`"a_text_file"` as a `String`,
89+
You can call `open()` on a DataSet to inspect the data inside. `open()` will
90+
return the [`Blob`](@ref) and [`BlobTree`](@ref) types for local files and
91+
directories on disk. For example,
9192

9293
```jldoctest
94+
julia> open(dataset("a_text_file"))
95+
📄 @ .../DataSets/docs/src/data/file.txt
96+
97+
julia> open(dataset("a_tree_example"))
98+
📂 Tree @ .../DataSets/docs/src/data/csvset
99+
📄 1.csv
100+
📄 2.csv
101+
```
102+
103+
Use the form `open(T, dataset)` to read the data as a specific type. `Blob`
104+
data can be opened as `String`, `IO`, or `Vector{UInt8}`, depending on your
105+
needs:
106+
107+
```jldoctest
108+
julia> io = open(IO, dataset("a_text_file"))
109+
IOStream(<file .../DataSets/docs/src/data/file.txt>)
110+
111+
julia> read(io, String)
112+
"Hello world!\n"
113+
114+
julia> buf = open(Vector{UInt8}, dataset("a_text_file"));
115+
116+
julia> String(buf)
117+
"Hello world!\n"
118+
93119
julia> open(String, dataset("a_text_file"))
94120
"Hello world!\n"
95121
```
96122

97-
It's also possible to open this data as an `IO` stream, in which case the do
98-
block form should be used:
123+
To ensure the dataset is closed again in a timely way (freeing any resources
124+
such as file handles), you should use the scoped form, for example:
99125

100126
```jldoctest
101127
julia> open(IO, dataset("a_text_file")) do io
@@ -106,10 +132,11 @@ julia> open(IO, dataset("a_text_file")) do io
106132
content = "Hello world!\n"
107133
```
108134

109-
Let's also inspect the tree example using the tree data type
110-
[`BlobTree`](@ref). Such data trees can be indexed with path components to get
111-
at the file [`Blob`](@ref)s inside, which in turn can be `open`ed to retrieve
112-
the data.
135+
Let's look at some tree-like data which is represented on local disk as a
136+
folder or directory. Tree data is opened in Julia as the [`BlobTree`](@ref)
137+
type and can be indexed with path components to get at the file [`Blob`](@ref)s
138+
inside. In turn, we can `open()` one of the file blobs and look at the data
139+
contained within.
113140

114141
```jldoctest
115142
julia> tree = open(BlobTree, dataset("a_tree_example"))
@@ -118,9 +145,9 @@ julia> tree = open(BlobTree, dataset("a_tree_example"))
118145
📄 2.csv
119146
120147
julia> tree["1.csv"]
121-
📄 1.csv @ .../DataSets/test/data/csvset
148+
📄 1.csv @ .../DataSets/docs/src/data/csvset
122149
123-
julia> Text(open(String, tree["1.csv"]))
150+
julia> open(String, tree["1.csv"]) |> Text
124151
Name,Age
125152
"Aaron",23
126153
"Harry",42

0 commit comments

Comments
 (0)