Skip to content

Commit

Permalink
feat: add flag to allow disabling auto decomression by client
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman committed Sep 11, 2019
1 parent fdf70bb commit af84737
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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;
}

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.only('should not gunzip the response if "retunCompressed: true" is passed', done => {
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

0 comments on commit af84737

Please sign in to comment.