Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a73265f
fix: revert skip validation
shaffeeullah Nov 18, 2021
a48fec7
fixed logic
shaffeeullah Nov 18, 2021
3adecd4
🦉 Updates from OwlBot
gcf-owl-bot[bot] Nov 18, 2021
0ab35dc
Merge branch 'main' of github.com:googleapis/nodejs-storage into shaf…
shaffeeullah Aug 8, 2022
253e2db
made updated change
shaffeeullah Aug 8, 2022
a92b8fb
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 8, 2022
3f00401
changed to ===
shaffeeullah Aug 8, 2022
c2ecda9
Merge branch 'shaffeeullah/revertskipvalidation' of github.com:google…
shaffeeullah Aug 8, 2022
8c004e7
fixed implementation
shaffeeullah Aug 9, 2022
470394b
Merge branch 'main' of github.com:googleapis/nodejs-storage into shaf…
shaffeeullah Aug 10, 2022
e8858fa
added comment
shaffeeullah Aug 10, 2022
dc58264
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 10, 2022
779020d
refactored boolean
shaffeeullah Aug 10, 2022
c350789
Merge branch 'main' of github.com:googleapis/nodejs-storage into shaf…
shaffeeullah Aug 10, 2022
ad7d7ae
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 10, 2022
fe1b81a
fixed bugs
shaffeeullah Aug 10, 2022
c8111c8
Merge branch 'shaffeeullah/revertskipvalidation' of github.com:google…
shaffeeullah Aug 10, 2022
875f675
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 10, 2022
f62880a
linted files
shaffeeullah Aug 10, 2022
0cb801f
Merge branch 'shaffeeullah/revertskipvalidation' of github.com:google…
shaffeeullah Aug 10, 2022
eb314f0
removed console.log
shaffeeullah Aug 10, 2022
2a5a02b
fixed unit tests
shaffeeullah Aug 10, 2022
66272aa
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 10, 2022
7de6158
added test
shaffeeullah Aug 12, 2022
da56822
Merge branch 'main' of github.com:googleapis/nodejs-storage into shaf…
shaffeeullah Aug 12, 2022
ac134f2
Merge branch 'main' into shaffeeullah/revertskipvalidation
shaffeeullah Sep 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ class File extends ServiceObject<File> {

const throughStream = streamEvents(new PassThrough());

let isServedCompressed = true;
let isCompressed = true;
let crc32c = true;
let md5 = false;

Expand Down Expand Up @@ -1470,7 +1470,7 @@ class File extends ServiceObject<File> {
rawResponseStream.on('error', onComplete);

const headers = rawResponseStream.toJSON().headers;
isServedCompressed = headers['content-encoding'] === 'gzip';
isCompressed = headers['content-encoding'] === 'gzip';
const throughStreams: Writable[] = [];

if (shouldRunValidation) {
Expand All @@ -1496,7 +1496,7 @@ class File extends ServiceObject<File> {
throughStreams.push(validateStream);
}

if (isServedCompressed && options.decompress) {
if (isCompressed && options.decompress) {
throughStreams.push(zlib.createGunzip());
}

Expand Down Expand Up @@ -1536,31 +1536,16 @@ class File extends ServiceObject<File> {
return;
}

// TODO(https://github.com/googleapis/nodejs-storage/issues/709):
// Remove once the backend issue is fixed.
// If object is stored compressed (having
// metadata.contentEncoding === 'gzip') and was served decompressed,
// then skip checksum validation because the remote checksum is computed
// against the compressed version of the object.
if (!isServedCompressed) {
try {
await this.getMetadata({userProject: options.userProject});
} catch (e) {
throughStream.destroy(e as Error);
return;
}
if (this.metadata.contentEncoding === 'gzip') {
throughStream.end();
return;
}
}
// Did the server decompress object before serving it back to us?
const serverDecompressed =
headers['x-goog-stored-content-encoding'] === 'gzip' && !isCompressed;

// 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.
let failed = crc32c || md5;

if (validateStream) {
if (validateStream && !serverDecompressed) {
Comment thread
shaffeeullah marked this conversation as resolved.
Outdated
if (crc32c && hashes.crc32c) {
failed = !validateStream.test('crc32c', hashes.crc32c);
}
Expand Down
35 changes: 0 additions & 35 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,41 +1443,6 @@ describe('File', () => {
.resume();
});

it('should pass the userProject to getMetadata', done => {
const fakeOptions = {
userProject: 'grapce-spaceship-123',
};

file.getMetadata = (options: GetFileMetadataOptions) => {
assert.strictEqual(options.userProject, fakeOptions.userProject);
setImmediate(done);
return Promise.resolve({
crc32c: CRC32C_HASH,
});
};

file.requestStream = getFakeSuccessfulRequest(DATA);

file.createReadStream(fakeOptions).on('error', done).resume();
});

it('should destroy stream from failed metadata fetch', done => {
const error = new Error('Error.');
file.getMetadata = () => {
return Promise.reject(error);
};

file.requestStream = getFakeSuccessfulRequest(DATA);

file
.createReadStream()
.on('error', (err: Error) => {
assert.strictEqual(err, error);
done();
})
.resume();
});

it('should validate with crc32c', done => {
file.requestStream = getFakeSuccessfulRequest(DATA);

Expand Down