Skip to content

Commit 04ec1cf

Browse files
authored
Update examples.md to use ZipArchives (#1158)
1 parent 9f95cfb commit 04ec1cf

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

docs/src/examples.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ file = CSV.File(http_response)
106106
## [Reading from a zip file](@id zip_example)
107107

108108
```julia
109-
using ZipFile, CSV, DataFrames
109+
using ZipArchives, Mmap, CSV, DataFrames
110110

111111
a = DataFrame(a = 1:3)
112112
CSV.write("a.csv", a)
@@ -116,22 +116,18 @@ CSV.write("a.csv", a)
116116
;zip a.zip a.csv
117117

118118
# alternatively, write directly into the zip archive (without creating an unzipped csv file first)
119-
z = ZipFile.Writer("a2.zip")
120-
f = ZipFile.addfile(z, "a.csv", method=ZipFile.Deflate)
121-
a |> CSV.write(f)
122-
close(z)
119+
ZipWriter("a2.zip") do z
120+
zip_newfile(z, "a.csv"; compress=true)
121+
a |> CSV.write(z)
122+
end
123123

124124
# read file from zip archive
125-
z = ZipFile.Reader("a.zip") # or "a2.zip"
125+
z = ZipReader(mmap(open("a.zip"))) # or "a2.zip"
126126

127127
# identify the right file in zip
128-
a_file_in_zip = filter(x->x.name == "a.csv", z.files)[1]
129-
130-
a_copy = CSV.File(a_file_in_zip) |> DataFrame
128+
a_copy = CSV.File(zip_openentry(z, "a.csv")) |> DataFrame
131129

132130
a == a_copy
133-
134-
close(z)
135131
```
136132

137133
## [Column names on 2nd row](@id second_row_header)

0 commit comments

Comments
 (0)