diff --git a/package.json b/package.json index ac73505bd2..a49ee9b657 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,6 @@ "@google-cloud/promisify": "^4.0.0", "abort-controller": "^3.0.0", "async-retry": "^1.3.3", - "compressible": "^2.0.12", "duplexify": "^4.1.3", "ent": "^2.2.0", "fast-xml-parser": "^4.3.0", @@ -96,7 +95,6 @@ "@grpc/grpc-js": "^1.0.3", "@grpc/proto-loader": "^0.7.0", "@types/async-retry": "^1.4.3", - "@types/compressible": "^2.0.0", "@types/ent": "^2.2.1", "@types/mime": "^3.0.0", "@types/mocha": "^9.1.1", diff --git a/src/file.ts b/src/file.ts index 1df546b93e..087795059b 100644 --- a/src/file.ts +++ b/src/file.ts @@ -24,7 +24,6 @@ import { } from './nodejs-common/index.js'; import {promisifyAll} from '@google-cloud/promisify'; -import compressible from 'compressible'; import * as crypto from 'crypto'; import * as fs from 'fs'; import mime from 'mime'; @@ -326,6 +325,24 @@ export const STORAGE_POST_POLICY_BASE_URL = 'https://storage.googleapis.com'; */ const GS_URL_REGEXP = /^gs:\/\/([a-z0-9_.-]+)\/(.+)$/; +/** + * @private + */ +const COMPRESSIBLE_MIME_REGEX = new RegExp( + [ + /^text\/|application\/ecmascript|application\/javascript|application\/json/, + /|application\/postscript|application\/rtf|application\/toml|application\/vnd.dart/, + /|application\/vnd.ms-fontobject|application\/wasm|application\/x-httpd-php|application\/x-ns-proxy-autoconfig/, + /|application\/x-sh(?!ockwave-flash)|application\/x-tar|application\/x-virtualbox-hdd|application\/x-virtualbox-ova|application\/x-virtualbox-ovf/, + /|^application\/x-virtualbox-vbox$|application\/x-virtualbox-vdi|application\/x-virtualbox-vhd|application\/x-virtualbox-vmdk/, + /|application\/xml|application\/xml-dtd|font\/otf|font\/ttf|image\/bmp|image\/vnd.adobe.photoshop|image\/vnd.microsoft.icon/, + /|image\/vnd.ms-dds|image\/x-icon|image\/x-ms-bmp|message\/rfc822|model\/gltf-binary|\+json|\+text|\+xml|\+yaml/, + ] + .map(r => r.source) + .join(''), + 'i' +); + export interface FileOptions { crc32cGenerator?: CRC32CValidatorGenerator; encryptionKey?: string | Buffer; @@ -1977,7 +1994,7 @@ class File extends ServiceObject { let gzip = options.gzip; if (gzip === 'auto') { - gzip = compressible(options!.metadata!.contentType || ''); + gzip = COMPRESSIBLE_MIME_REGEX.test(options!.metadata!.contentType || ''); } if (gzip) {