ncw/swift

Feature Request: Get MD5 hash from Closed ObjectCreateFile struct

whereswaldon opened this issue · 5 comments

I've been writing a lot of code to build SLO manifest files from smaller chunks of data. I need the MD5 hash of each chunk for its manifest entry. Right now, even though the connection.ObjectCreate can check the MD5 hash for me, I can't get its value, so I have to redundantly compute it. I know that I can pull it down after the upload completes with connection.Object, but I'd rather not make the HTTP request. Could a method be added to the ObjectCreateFile struct that exposes the computed hash? Perhaps something like:

// Etag returns the MD5 hash of a successful upload. If it is called before
// an upload is closed or on an unsuccessful upload, it will return an error
// and an undefined byte slice.
func (file *ObjectCreateFile) Etag() ([]byte, error)
ncw commented

Seems like a sensible idea.

Perhaps more general purpose would be

// Headers returns the HTTP headers of a successful upload. If it is called before
// an upload is Close()ed or on an unsuccessful upload, it will return a nil map and an error.
func (file *ObjectCreateFile) Headers() (Headers, error)

Or possibly even better would be this as the Object has a Hash field, but is useful for other things...

// Object returns the Object for a successful upload. If it is called before
// an upload is Close()ed or on an unsuccessful upload, it will return a
// nil Object and an error.
func (file *ObjectCreateFile) Object() (*Object, error)

I quite like the second one. How difficult would the implementation be?

ncw commented

I quite like the second one. How difficult would the implementation be?

It would be quite straight forward - fancy having a go?

Do you have any suggestions on how to fill out the PseudoDirectory and SubDir fields on the returned Object struct from the information at hand? I can see how to get all of the other properties of the Object from the ObjectOpenFile, but not those two.

ncw commented

You can set PseudoDirectory to false and SubDir to empty string - these are only relevant when listing directory objects.