简体   繁体   English

如何用JavaScript解压缩SVGZ?

[英]How to decompress SVGZ with JavaScript?

I'm trying to set up this world map using SVGZ instead of SVG so I can give my users a richer, more detailed map. 我正在尝试使用SVGZ而不是SVG设置此世界地图,以便为用户提供更丰富,更详细的地图。

So far I've tried decompressing it using js-deflate , but to no avail. 到目前为止,我尝试使用js-deflate将其解压缩 ,但无济于事。

If you want the SVG file inside of the SVGZ, you gunzip it (it's a renamed archive): 如果你想SVGZ 的SVG文件,你用gunzip它(这是一个重命名的档案):

cp file.svgz file2.svg.gz
gunzip file2.svg.gz

If you want to use a SVGZ image, then you might run into trouble. 如果要使用 SVGZ图像,则可能会遇到麻烦。 I think some browsers support it (virtually all support Gzip compression), but I doubt many do (if any at all). 我认为有些浏览器支持它(实际上都支持Gzip压缩),但我怀疑许多浏览器是否支持(如果有的话)。

As I write in comment SVGZ uses gzip . 正如我在评论中写道,SVGZ使用gzip Top browsers can decompress gzip files without assistance. 顶级浏览器可以在没有帮助的情况下解压缩gzip文件。 Your page http://home.no/dwaynie/map load .svgz file with Content-Type:text/plain; charset=ISO-8859-1 您的页面http://home.no/dwaynie/map加载具有Content-Type:text/plain; charset=ISO-8859-1 .svgz文件Content-Type:text/plain; charset=ISO-8859-1 Content-Type:text/plain; charset=ISO-8859-1 . Content-Type:text/plain; charset=ISO-8859-1 But for SVG | 但是对于SVG | SVGZ it's not valid MIME type. SVGZ这不是有效的MIME类型。

svg     Content-Type: image/svg+xml

svgz    Content-Type: image/svg+xml
        Content-Encoding: gzip

Above headers must be configured in web server (IIS, Apache). 以上标头必须在Web服务器(IIS,Apache)中配置。

Just below the map on the page you refer to there's a link to Wikipedia that explains what it is: an SVG file compressed with gzip. 在您所引用的页面地图下方,有一个指向Wikipedia的链接,该链接解释了这是什么:用gzip压缩的SVG文件。

For completeness sake: gzip and (pk)zip are not the same format, but Windows tools like WinRAR and 7-Zip understand gzip as well as zip. 出于完整性考虑:gzip和(pk)zip格式不同,但是Windows工具(如WinRAR和7-Zip)可以理解gzip和zip。 Every Linux distro probably has gzip/gunzip installed by default. 每个Linux发行版可能默认都安装了gzip / gunzip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM