Skip to content

Commit 40e67b7

Browse files
authored
Merge pull request #110 from JuliaLinearAlgebra:krc/channelbuffers031
Adapt to ChannelBuffers v0.3.1
2 parents a1d826c + bcdf1cb commit 40e67b7

File tree

3 files changed

+18
-33
lines changed

3 files changed

+18
-33
lines changed

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MatrixDepot"
22
uuid = "b51810bb-c9f3-55da-ae3c-350fc1fbce05"
3-
version = "1.0.9"
3+
version = "1.0.10"
44

55
[deps]
66
ChannelBuffers = "79a69506-cdd1-4876-b8e5-7af85e53af4f"
@@ -14,7 +14,7 @@ Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1414
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1515

1616
[compat]
17-
ChannelBuffers = "0.2, 0.3"
17+
ChannelBuffers = "0.3.1"
1818
DataFrames = "0.20, 0.22, 0.21, 1.1, 1.2, 1.3, 1.4, 1.5"
1919
MAT = "0.7, 0.8, 0.9, 0.10"
2020
Scratch = "1"

src/download.jl

+11-11
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function loadmatrix(data::RemoteMatrixData)
133133
try
134134
@info("downloading: $url")
135135
pipe = downloadpipeline(url, dirt)
136-
wait(run(pipe))
136+
run(pipe)
137137
cd(dirt)
138138
for file in readdir(dirt)
139139
mv(file, joinpath(dir, file), force=true)
@@ -164,14 +164,12 @@ function loadinfo(data::RemoteMatrixData)
164164
return 0
165165
end
166166
url = redirect(dataurl(data))
167-
io = ChannelPipe()
168-
pipe = downloadpipeline(url, io)
169-
tl = run(pipe)
167+
io = open(downloadpipeline(url))
170168
out = IOBuffer()
171169
s = try
172170
@info("downloading head of $url")
173171
skip = 0
174-
while ( s = readskip(io) ) != ""
172+
while ( s = readline(io) ) != ""
175173
skip = s[1] == '%' || isempty(strip(s)) ? 0 : skip + 1
176174
skip <= 1 && println(out, s)
177175
if skip == 1 && length(split(s)) == 3
@@ -183,7 +181,7 @@ function loadinfo(data::RemoteMatrixData)
183181
ex isa InterruptException && rethrow()
184182
String(take!(out))
185183
finally
186-
close(out)
184+
close(io)
187185
end
188186
if !isempty(s)
189187
mkpath(dirname(file))
@@ -197,11 +195,13 @@ end
197195
loadinfo(data::MatrixData) = 0
198196

199197
"""
200-
downloadpipeline(url)
198+
downloadpipeline(url, path=nothing)
201199
202200
Set up a command pipeline (external processes to download and expand data)
201+
If a path name is given, extract tar file into the empty directory or, if
202+
not a tar file, write contents to file of that name.
203203
"""
204-
function downloadpipeline(url::AbstractString, dir=nothing)
204+
function downloadpipeline(url::AbstractString, dir::Union{Nothing,AbstractString}=nothing)
205205
urls = rsplit(url, '.', limit=3)
206206
cmd = Any[ChannelBuffers.curl(url)]
207207
if urls[end] == "gz"
@@ -216,8 +216,8 @@ function downloadpipeline(url::AbstractString, dir=nothing)
216216
file = rsplit(url, '/', limit=2)
217217
push!(cmd, joinpath(dir, file[end]))
218218
end
219-
elseif dir isa ChannelPipe
220-
push!(cmd, dir)
219+
elseif dir === nothing && urls[end] == "tar"
220+
push!(cmd, tarxO())
221221
end
222222
pipeline(cmd...)
223223
end
@@ -321,6 +321,6 @@ issvdok(::MatrixData) = false
321321
Copy file from remote or local url. Works around julia Downloads #69 and #36
322322
"""
323323
function downloadfile(url::AbstractString, out::AbstractString)
324-
wait(run(downloadcommand(url, out)))
324+
run(downloadcommand(url, out))
325325
nothing
326326
end

src/matrixmarket.jl

+5-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const HERMITIAN = "hermitian"
3232
const SKEW_SYMMETRIC = "skew-symmetric"
3333

3434
function mmread(file::IO)
35-
line = lowercase(readskip(file))
35+
line = lowercase(readline(file))
3636
tokens = split(line)
3737
if length(tokens) < 2 || tokens[1] != MATRIXM
3838
parserr(string("Matrixmarket: invalid header:", line))
@@ -241,7 +241,7 @@ function mmreadcomment(filename::AbstractString)
241241
open(filename,"r") do mmfile
242242
skip = 0
243243
while !eof(mmfile)
244-
s = readskip(mmfile)
244+
s = readline(mmfile)
245245
skip = isempty(strip(s)) || s[1] == '%' ? 0 : skip + 1
246246
skip <= 1 && println(io, s)
247247
if skip == 1
@@ -254,21 +254,6 @@ function mmreadcomment(filename::AbstractString)
254254
String(take!(io))
255255
end
256256

257-
"""
258-
readskip(io)
259-
260-
Read a line. If line starts with a ustar-header block remove this block.
261-
This allows to read through a tar archive without extracting the files.
262-
"""
263-
function readskip(io::IO)
264-
max = 512
265-
line = readline(io)
266-
if length(line) >= max && line[258:263] == "ustar\0"
267-
line = line[max+1:end]
268-
end
269-
line
270-
end
271-
272257
"""
273258
mmreadheader(filename)
274259
Read header information from mtx file.
@@ -279,7 +264,7 @@ function mmreadheader(file::AbstractString)
279264
if stat(io).size == 0
280265
return nothing
281266
end
282-
line = lowercase(readskip(io))
267+
line = lowercase(readline(io))
283268
while true
284269
token = split(line)
285270
if length(token) >= 4 &&
@@ -291,7 +276,7 @@ function mmreadheader(file::AbstractString)
291276
field = :none
292277
while startswith(line, '%') || isempty(strip(line))
293278
field = push_hdr!(hdr, line, field)
294-
line = readskip(io)
279+
line = readline(io)
295280
end
296281
res = try parseint(line) catch; [] end
297282
if length(res) != (token[3] == COORD ? 3 : 2)
@@ -314,7 +299,7 @@ function mmreadheader(file::AbstractString)
314299
return hdr
315300
else
316301
while !eof(io) && !startswith(line, '%')
317-
line = readskip(io)
302+
line = readline(io)
318303
end
319304
if eof(io)
320305
return hdr

0 commit comments

Comments
 (0)