Skip to content

Commit

Permalink
Add support for URIs (#302)
Browse files Browse the repository at this point in the history
User must load HTTP manually for this to be activated.
(It exploits Requires.)

Closes #219
Closes #89
  • Loading branch information
timholy authored Mar 3, 2021
1 parent 1d9d382 commit 79a49d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.6.0"

[deps]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
Expand All @@ -12,8 +13,9 @@ julia = "0.7, 1"
[extras]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ColorTypes", "FilePathsBase", "Random", "Test"]
test = ["ColorTypes", "FilePathsBase", "HTTP", "Random", "Test"]
7 changes: 7 additions & 0 deletions src/FileIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Base.showerror
using Base: RefValue, PkgId
using Pkg
using UUIDs
using Requires

include("types.jl")
include("registry_setup.jl")
Expand Down Expand Up @@ -63,6 +64,12 @@ include("registry.jl")
"""
FileIO

function __init__()
@require HTTP="cd3eb016-35fb-5094-929b-558a96fad6f3" begin
load(uri::HTTP.URI) = load(IOBuffer(HTTP.get(uri).body))
end
end

if VERSION >= v"1.4.2" # https://github.com/JuliaLang/julia/pull/35378
include("precompile.jl")
_precompile_()
Expand Down
6 changes: 5 additions & 1 deletion test/integration.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using FileIO
using ColorTypes
using ColorTypes.FixedPointNumbers
using HTTP
using Pkg
using Test

@testset "Integration" begin
if haskey(ENV, "CI") && Base.VERSION >= v"1.3"
if haskey(ENV, "CI") && Base.VERSION >= v"1.3" # ImageIO can't be loaded on Julia < 1.3, so putting it as test dep is problematic
Pkg.add("ImageIO")
img = rand(RGB{N0f8}, 50, 50)
io = IOBuffer()
Expand All @@ -14,5 +15,8 @@ using Test
io2 = IOBuffer(buf)
img2 = load(io2)
@test img2 == img

uri = HTTP.URI("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Wikipedia-logo-v2-en.svg/135px-Wikipedia-logo-v2-en.svg.png")
@test isa(load(uri), Matrix)
end
end

0 comments on commit 79a49d4

Please sign in to comment.