From 8c6d9fdc622d3c9c145b23b7b13e4f9bce073332 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sat, 12 Jun 2021 15:09:51 +0100 Subject: [PATCH] Install: always use Brotli-compressed tarballs --- docs/install.md | 8 ++------ install/libvips.js | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/install.md b/docs/install.md index bc2e78a7..804d5ffc 100644 --- a/docs/install.md +++ b/docs/install.md @@ -138,14 +138,10 @@ To install the prebuilt libvips binaries from a custom URL, set the `sharp_libvips_binary_host` npm config option or the `npm_config_sharp_libvips_binary_host` environment variable. -The version subpath and file name are appended to these. There should be tarballs available -that are compressed with both gzip and Brotli, as the format downloaded will vary depending -on whether the user's version of Node supports Brotli decompression (Node.js v10.16.0+) - +The version subpath and file name are appended to these. For example, if `sharp_libvips_binary_host` is set to `https://hostname/path` and the libvips version is `1.2.3` then the resultant URL will be -`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.br` or -`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.gz`. +`https://hostname/path/v1.2.3/libvips-1.2.3-platform-arch.tar.br`. See the Chinese mirror below for a further example. diff --git a/install/libvips.js b/install/libvips.js index 098c61e8..e813e8f7 100644 --- a/install/libvips.js +++ b/install/libvips.js @@ -35,7 +35,6 @@ const hasSharpPrebuild = [ const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download'; const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`; -const supportsBrotli = ('BrotliDecompress' in zlib); const installationForced = !!(process.env.npm_config_sharp_install_force || process.env.SHARP_INSTALL_FORCE); const fail = function (err) { @@ -68,7 +67,7 @@ const extractTarball = function (tarPath, platformAndArch) { stream.pipeline( fs.createReadStream(tarPath), - supportsBrotli ? new zlib.BrotliDecompress() : new zlib.Gunzip(), + new zlib.BrotliDecompress(), tarFs.extract(versionedVendorPath, { ignore }), function (err) { if (err) { @@ -121,10 +120,8 @@ try { handleError(new Error(`Expected Node.js version ${supportedNodeVersion} but found ${process.versions.node}`)); } - const extension = supportsBrotli ? 'br' : 'gz'; - // Download to per-process temporary file - const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.' + extension; + const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.br'; const tarPathCache = path.join(libvips.cachePath(), tarFilename); if (fs.existsSync(tarPathCache)) { libvips.log(`Using cached ${tarPathCache}`);