Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to allow disabling auto decompression by client #850

Merged
merged 14 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 6 additions & 1 deletion src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export interface CreateReadStreamOptions {
validation?: 'md5' | 'crc32c' | false | true;
start?: number;
end?: number;
returnCompressed?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about decompress, default true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

export interface SaveOptions extends CreateWriteStreamOptions {}
Expand Down Expand Up @@ -1112,6 +1113,10 @@ class File extends ServiceObject<File> {
* NOTE: Byte ranges are inclusive; that is, `options.start = 0` and
* `options.end = 999` represent the first 1000 bytes in a file or object.
* NOTE: when specifying a byte range, data integrity is not available.
* @property {booblean} [returnCompressed] Disable auto decompression of the
* received data. By default this option set to `false`.
* Applicable in cases where the data was uploaded with
* `gzip: true` option. See {@link File#createWriteStream}.
*/
/**
* Create a readable stream to read the contents of the remote file. It can be
Expand Down Expand Up @@ -1304,7 +1309,7 @@ class File extends ServiceObject<File> {
throughStreams.push(validateStream);
}

if (isCompressed) {
if (isCompressed && !options.returnCompressed) {
throughStreams.push(zlib.createGunzip());
}

Expand Down
11 changes: 11 additions & 0 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,17 @@ describe('File', () => {
.resume();
});

it('should not gunzip the response if "retunCompressed: true" is passed', done => {
jkwlui marked this conversation as resolved.
Show resolved Hide resolved
file
.createReadStream({returnCompressed: true})
.once('error', done)
.on('data', (data: {}) => {
assert.strictEqual(data, GZIPPED_DATA);
done();
})
.resume();
});

it('should emit errors from the gunzip stream', done => {
const error = new Error('Error.');
const createGunzipStream = through();
Expand Down