Skip to content

Commit

Permalink
remove compressible dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Apr 8, 2024
1 parent 00df71a commit 5812958
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
21 changes: 19 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1977,7 +1994,7 @@ class File extends ServiceObject<File, FileMetadata> {
let gzip = options.gzip;

if (gzip === 'auto') {
gzip = compressible(options!.metadata!.contentType || '');
gzip = COMPRESSIBLE_MIME_REGEX.test(options!.metadata!.contentType || '');
}

if (gzip) {
Expand Down

0 comments on commit 5812958

Please sign in to comment.