Skip to content

GODRIVER-1548 Add gridfs.File type #353

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

Merged
merged 2 commits into from
Apr 2, 2020

Conversation

divjotarora
Copy link
Contributor

No description provided.

@@ -161,6 +215,11 @@ func (ds *DownloadStream) Skip(skip int64) (int64, error) {
return skip, nil
}

// GetFile returns a File object representing the file being downloaded.
func (ds *DownloadStream) GetFile() File {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the file meant to not be stored as a pointer? Couldn't the metadata be quite large. This would end up with a copy every time you get the file instead of just copying the pointer.

ie return *File instead and store as a pointer to the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted to return a value instead of a pointer because the DownloadStream type uses parts of the file (e.g. the file length) and offering a pointer would let a user mutate the stream's state. The stream doesn't validate its state after creation because it's not mutable by users, so this could cause problems with unknown consequences.

If you're concerned about metadata size, I can update the DownloadStream type to store the relevant information it needs from File upon creation and then return a pointer to the underlying File. That way, it's not accessing anything that's potentially been mutated by a user and also avoiding the large copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that is a good concern.

Metadata doesn't really have any size limits besides the total bson doc limit and considering most fields have been pushed into it + not wanting to limit how people use the metadata. Anyways I think it'd be a good idea to not tie ourselves into supporting a potential issue here.

I would say either update to a pointer with a clear comment that all fields are read only(you could modify metadata after unmarshaling if you wished though safely) or implement your internal copy idea. Either way I'd say release as with a *File even if it's just a comment preventing bad usage for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to store/return a *File and defensively copy the necessary fields in newDownloadStream.

@epelc
Copy link
Contributor

epelc commented Apr 2, 2020

LGTM I propose storing/returning the File as a *File instead though to reduce copying unless you have objections.

@jyemin jyemin removed their request for review April 2, 2020 21:07
@divjotarora divjotarora merged commit 32066ed into mongodb:master Apr 2, 2020
@divjotarora divjotarora deleted the godriver1548-gfs-metadata branch April 2, 2020 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants