@google-cloud/storage
Advanced tools
Comparing version 6.9.3 to 6.9.4
@@ -230,3 +230,3 @@ /// <reference types="node" /> | ||
} | ||
declare class RequestError extends Error { | ||
export declare class RequestError extends Error { | ||
code?: string; | ||
@@ -233,0 +233,0 @@ errors?: Error[]; |
@@ -6,5 +6,14 @@ /// <reference types="node" /> | ||
interface HashStreamValidatorOptions { | ||
/** Enables CRC32C calculation. To validate a provided value use `crc32cExpected`. */ | ||
crc32c: boolean; | ||
/** Enables MD5 calculation. To validate a provided value use `md5Expected`. */ | ||
md5: boolean; | ||
/** Set a custom CRC32C generator */ | ||
crc32cGenerator: CRC32CValidatorGenerator; | ||
/** Sets the expected CRC32C value to verify once all data has been consumed. Also sets the `crc32c` option to `true` */ | ||
crc32cExpected?: string; | ||
/** Sets the expected MD5 value to verify once all data has been consumed. Also sets the `md5` option to `true` */ | ||
md5Expected?: string; | ||
/** Indicates whether or not to run a validation check or only update the hash values */ | ||
updateHashesOnly?: boolean; | ||
} | ||
@@ -15,4 +24,7 @@ declare class HashStreamValidator extends Transform { | ||
readonly md5Enabled: boolean; | ||
readonly crc32cExpected: string | undefined; | ||
readonly md5Expected: string | undefined; | ||
readonly updateHashesOnly: boolean; | ||
constructor(options?: Partial<HashStreamValidatorOptions>); | ||
_flush(callback: () => void): void; | ||
_flush(callback: (error?: Error | null | undefined) => void): void; | ||
_transform(chunk: Buffer, encoding: BufferEncoding, callback: (e?: Error) => void): void; | ||
@@ -19,0 +31,0 @@ test(hash: 'crc32c' | 'md5', sum: Buffer | string): boolean; |
@@ -32,5 +32,7 @@ "use strict"; | ||
const crc32c_1 = require("./crc32c"); | ||
const file_1 = require("./file"); | ||
class HashStreamValidator extends stream_1.Transform { | ||
constructor(options = {}) { | ||
super(); | ||
this.updateHashesOnly = false; | ||
_HashStreamValidator_crc32cHash.set(this, undefined); | ||
@@ -41,2 +43,5 @@ _HashStreamValidator_md5Hash.set(this, undefined); | ||
this.md5Enabled = !!options.md5; | ||
this.updateHashesOnly = !!options.updateHashesOnly; | ||
this.crc32cExpected = options.crc32cExpected; | ||
this.md5Expected = options.md5Expected; | ||
if (this.crc32cEnabled) { | ||
@@ -54,3 +59,26 @@ const crc32cGenerator = options.crc32cGenerator || crc32c_1.CRC32C_DEFAULT_VALIDATOR_GENERATOR; | ||
} | ||
callback(); | ||
if (this.updateHashesOnly) { | ||
callback(); | ||
return; | ||
} | ||
// If we're doing validation, assume the worst-- a data integrity | ||
// mismatch. If not, these tests won't be performed, and we can assume | ||
// the best. | ||
// We must check if the server decompressed the data on serve because hash | ||
// validation is not possible in this case. | ||
let failed = this.crc32cEnabled || this.md5Enabled; | ||
if (this.crc32cEnabled && this.crc32cExpected) { | ||
failed = !this.test('crc32c', this.crc32cExpected); | ||
} | ||
if (this.md5Enabled && this.md5Expected) { | ||
failed = !this.test('md5', this.md5Expected); | ||
} | ||
if (failed) { | ||
const mismatchError = new file_1.RequestError(file_1.FileExceptionMessages.DOWNLOAD_MISMATCH); | ||
mismatchError.code = 'CONTENT_DOWNLOAD_MISMATCH'; | ||
callback(mismatchError); | ||
} | ||
else { | ||
callback(); | ||
} | ||
} | ||
@@ -57,0 +85,0 @@ _transform(chunk, encoding, callback) { |
{ | ||
"name": "@google-cloud/storage", | ||
"description": "Cloud Storage Client Library for Node.js", | ||
"version": "6.9.3", | ||
"version": "6.9.4", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google Inc.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
836832
16891