Skip to content

Commit

Permalink
feat: Also auto compress filenames ending in ".gz" (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorld authored Mar 7, 2023
1 parent 7ac32e8 commit d772034
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions src/SvgStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down

0 comments on commit d772034

Please sign in to comment.