diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4d78033..aa38689bb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * 【poi 】 增加GlobalPoiConfig(issue#IAEHJH@Gitee) * 【core 】 优化IndexedComparator性能(pr#1240@Gitee) * 【http 】 改进ContentType.get忽略空格(pr#3664@Github) +* 【http 】 CompressUtil.createExtractor支持tgz自动识别(pr#3674@Github) ### 🐞Bug修复 * 【core 】 修复因RFC3986理解有误导致的UrlPath处理冒号转义问题(issue#IAAE88@Gitee) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/compress/CompressUtil.java b/hutool-extra/src/main/java/cn/hutool/extra/compress/CompressUtil.java index c19367ca5..72cc22bf6 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/compress/CompressUtil.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/compress/CompressUtil.java @@ -170,12 +170,16 @@ public class CompressUtil { if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(archiverName)) { return new SevenZExtractor(file); } - try { - if (StrUtil.isBlank(archiverName) && file.getName().toLowerCase().endsWith(".tgz")) { + + if(StrUtil.isBlank(archiverName)){ + final String name = file.getName().toLowerCase(); + if(name.endsWith(".tgz")){ archiverName = "tgz"; - } else if (StrUtil.isBlank(archiverName) && file.getName().toLowerCase().endsWith(".tar.gz")) { + } else if(name.endsWith(".tar.gz")){ archiverName = "tar.gz"; } + } + try { return new StreamExtractor(charset, archiverName, file); } catch (CompressException e) { final Throwable cause = e.getCause();