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 8 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
22 changes: 8 additions & 14 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,23 +1536,17 @@ 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) {
// Did the server decompress object before serving it back to us?
const serverDecompressed =
headers['x-goog-stored-content-encoding'] === 'gzip' && !isCompressed;

if (serverDecompressed) {
Comment thread
shaffeeullah marked this conversation as resolved.
Outdated
try {
await this.getMetadata({userProject: options.userProject});
} catch (e) {
throughStream.destroy(e as Error);
return;
}
if (this.metadata.contentEncoding === 'gzip') {
throughStream.end();
return;
}
}

// If we're doing validation, assume the worst-- a data integrity
Expand Down
27 changes: 0 additions & 27 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2516,33 +2516,6 @@ describe('storage', () => {
await file.delete();
});

it('should skip validation if file is served decompressed', async () => {
const filename = 'logo-gzipped.png';
await bucket.upload(FILES.logo.path, {destination: filename, gzip: true});

tmp.setGracefulCleanup();
const {name: tmpFilePath} = tmp.fileSync();

const file = bucket.file(filename);

await new Promise((resolve, reject) => {
file
.createReadStream()
.on('error', reject)
.on('response', raw => {
assert.strictEqual(
raw.toJSON().headers['content-encoding'],
undefined
);
})
.pipe(fs.createWriteStream(tmpFilePath))
.on('error', reject)
.on('finish', resolve);
});

await file.delete();
});
Comment thread
shaffeeullah marked this conversation as resolved.

describe('simple write', () => {
it('should save arbitrary data', done => {
const file = bucket.file('TestFile');
Expand Down
13 changes: 0 additions & 13 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,19 +1395,6 @@ describe('File', () => {
};
}

describe('server decompression', () => {
it('should skip validation if file was stored compressed', done => {
file.metadata.crc32c = '.invalid.';
Comment thread
shaffeeullah marked this conversation as resolved.
file.metadata.contentEncoding = 'gzip';

file
.createReadStream({validation: 'crc32c'})
.on('error', done)
.on('end', done)
.resume();
});
});

it('should emit errors from the validation stream', done => {
const expectedError = new Error('test error');

Expand Down