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 all commits
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
2 changes: 1 addition & 1 deletion src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ class File extends ServiceObject<File, FileMetadata> {
cb = optionsOrCallback as DownloadCallback;
options = {};
} else {
options = optionsOrCallback as DownloadOptions;
options = Object.assign({}, optionsOrCallback);
}

let called = false;
Expand Down
19 changes: 17 additions & 2 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2596,11 +2596,26 @@ describe('File', () => {
file.download({}, assert.ifError);
});

it('should not mutate options object after use', done => {
const optionsObject = {destination: './unknown.jpg'};
fileReadStream._read = () => {
assert.strictEqual(optionsObject.destination, './unknown.jpg');
assert.deepStrictEqual(optionsObject, {destination: './unknown.jpg'});
done();
};
file.download(optionsObject, assert.ifError);
});

it('should pass the provided options to createReadStream', done => {
const readOptions = {start: 100, end: 200};
const readOptions = {start: 100, end: 200, destination: './unknown.jpg'};

file.createReadStream = (options: {}) => {
assert.deepStrictEqual(options, readOptions);
assert.deepStrictEqual(options, {start: 100, end: 200});
assert.deepStrictEqual(readOptions, {
start: 100,
end: 200,
destination: './unknown.jpg',
});
done();
return fileReadStream;
};
Expand Down