10
10
DocTestFilters = [
11
11
r"(?<=Project: \[).*$",
12
12
r"path =.*",
13
- r"@.*"
13
+ r"@.*",
14
+ r"(?<=IOStream\().*",
14
15
]
15
16
```
16
17
@@ -85,17 +86,42 @@ path = ".../DataSets/docs/src/data/file.txt"
85
86
86
87
## Loading Data
87
88
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 ,
91
92
92
93
``` 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
+
93
119
julia> open(String, dataset("a_text_file"))
94
120
"Hello world!\n"
95
121
```
96
122
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 :
99
125
100
126
``` jldoctest
101
127
julia> open(IO, dataset("a_text_file")) do io
@@ -106,10 +132,11 @@ julia> open(IO, dataset("a_text_file")) do io
106
132
content = "Hello world!\n"
107
133
```
108
134
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.
113
140
114
141
``` jldoctest
115
142
julia> tree = open(BlobTree, dataset("a_tree_example"))
@@ -118,9 +145,9 @@ julia> tree = open(BlobTree, dataset("a_tree_example"))
118
145
📄 2.csv
119
146
120
147
julia> tree["1.csv"]
121
- 📄 1.csv @ .../DataSets/test /data/csvset
148
+ 📄 1.csv @ .../DataSets/docs/src /data/csvset
122
149
123
- julia> Text( open(String, tree["1.csv"]))
150
+ julia> open(String, tree["1.csv"]) |> Text
124
151
Name,Age
125
152
"Aaron",23
126
153
"Harry",42
0 commit comments