压缩gzip文件问题

compress gzip file issue

我目前正在使用 jszip 压缩文件,但文件已损坏,因为我将其压缩为 zip 文件。 但后端只能解压缩 gzip 文件。 我在前端使用 vue js。

                   let zip = new jszip();
                    zip.file(fileToCompress.name, fileToCompress);
                    let component = this;

                    zip.generateAsync({type: "blob", compression: "DEFLATE"}).then(function(zipedFile) {
send to the back end
}

如何将其压缩为 gzip?有我可以使用的图书馆吗?或者我可以使用一些 jszip?如果可以,我该怎么做?

您可以尝试 pako 包,它支持 gzip。参见 gzip method

gzip(data[, options]) -> Uint8Array