From 87e8eec480aa06cf3a2d605af626a44311510249 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 19 Mar 2021 14:30:34 +0100 Subject: [PATCH] fix fileio ambig JuliaPlots/Makie.jl#894 --- src/display.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/display.jl b/src/display.jl index dd44e481a..b3ca16545 100644 --- a/src/display.jl +++ b/src/display.jl @@ -202,6 +202,7 @@ format2mime(::Type{FileIO.format"HTML"}) = MIME("text/html") filetype(::FileIO.File{F}) where F = F # Allow format to be overridden with first argument + """ FileIO.save(filename, scene; resolution = size(scene), pt_per_unit = 1.0, px_per_unit = 1.0) @@ -225,13 +226,20 @@ Save a `Scene` with the specified filename and format. - `px_per_unit`: The size of one scene unit in `px` when exporting to a bitmap format. This provides a mechanism to export the same scene with higher or lower resolution. """ function FileIO.save( - filename, fig::FigureLike; + filename::String, fig::FigureLike; args... + ) + FileIO.save(FileIO.query(filename), fig; args...) +end + +function FileIO.save( + file::FileIO.Formatted, fig::FigureLike; resolution = size(get_scene(fig)), pt_per_unit = 1.0, px_per_unit = 1.0, ) scene = get_scene(fig) resolution != size(scene) && resize!(scene, resolution) + filename = FileIO.filename(file) # Delete previous file if it exists and query only the file string for type. # We overwrite existing files anyway, so this doesn't change the behavior. # But otherwise we could get a filetype :UNKNOWN from a corrupt existing file @@ -239,7 +247,7 @@ function FileIO.save( # type readout from an existing file. isfile(filename) && rm(filename) # query the filetype only from the file extension - F = filetype(FileIO.query(filename)) + F = filetype(file) open(filename, "w") do s iocontext = IOContext(s,