From d77203467dcfbed9b5ca40ae38075fcbe2a032ab Mon Sep 17 00:00:00 2001 From: Trevor L Davis Date: Tue, 7 Mar 2023 02:41:57 -0800 Subject: [PATCH] feat: Also auto compress filenames ending in ".gz" (#163) --- README.Rmd | 2 +- README.md | 2 +- src/SvgStream.h | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.Rmd b/README.Rmd index 7565259..13e3256 100644 --- a/README.Rmd +++ b/README.Rmd @@ -74,7 +74,7 @@ fs::file_size(tmp1) fs::file_size(tmp2) ``` -In both cases, compressing to make `.svgz` (gzipped svg) is worthwhile. svglite supports compressed output directly which will be triggered if the provided path has a `".svgz"` extension. +In both cases, compressing to make `.svgz` (gzipped svg) is worthwhile. svglite supports compressed output directly which will be triggered if the provided path has a `".svgz"` (or `".svg.gz"`) extension. ```{r} tmp3 <- tempfile(fileext = ".svgz") diff --git a/README.md b/README.md index b4ebb85..d1070d5 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ fs::file_size(tmp2) In both cases, compressing to make `.svgz` (gzipped svg) is worthwhile. svglite supports compressed output directly which will be triggered if -the provided path has a `".svgz"` extension. +the provided path has a `".svgz"` (or `".svg.gz"`) extension. ``` r tmp3 <- tempfile(fileext = ".svgz") diff --git a/src/SvgStream.h b/src/SvgStream.h index 8e9a451..4858a72 100644 --- a/src/SvgStream.h +++ b/src/SvgStream.h @@ -83,7 +83,8 @@ class SvgStreamFile : public SvgStream { public: SvgStreamFile(const std::string& path, bool _always_valid = false) : always_valid(_always_valid) { std::string svgz_ext = path.size() > 5 ? path.substr(path.size() - 5) : ""; - compress = iequals(svgz_ext, ".svgz"); + std::string gz_ext = path.size() > 3 ? path.substr(path.size() - 3) : ""; + compress = iequals(svgz_ext, ".svgz") || iequals(gz_ext, ".gz"); file = R_ExpandFileName(path.c_str()); stream_.open(file.c_str()); @@ -96,7 +97,8 @@ class SvgStreamFile : public SvgStream { SvgStreamFile(const std::string& path, int pageno, bool _always_valid = false) : always_valid(_always_valid) { std::string svgz_ext = path.size() > 5 ? path.substr(path.size() - 5) : ""; - compress = iequals(svgz_ext, ".svgz"); + std::string gz_ext = path.size() > 3 ? path.substr(path.size() - 3) : ""; + compress = iequals(svgz_ext, ".svgz") || iequals(gz_ext, ".gz"); char buf[PATH_MAX+1]; snprintf(buf, PATH_MAX, path.c_str(), pageno);