Giter VIP home page Giter VIP logo

calculate_multipart_etag's Introduction

DESCRPTION:

	Given a file and a chunk size in megabytes, calculates what the Amazon S3 etag will be.



	Amazon uses a simple md5 sum for an etag on single part uploads, but on multipart uploads they use a scheme of:
		md5ing the chunks,
		globbing the md5s together,
		converting the md5s to binary
		md5ing the binary of the chunks
		and appending -<Number_of_chunks> to the end

	This can make comparing files in s3 to local copies without downloading them a pain.

	The process to generate them is just convoluted enough that there's a lot of confused people out there on the forums.
	Lots of speculation, not much code examples other than some bash tools.

	It works from the command line, or import the function into your own code and use it there.

	Tested on python 3.4, but should work on 2.6+ unless I missed something obvious.

	Big thanks to antespi for his bash tool that does the same thing.
		 https://github.com/antespi/s3md5



USAGE:
	python calculate_multipart_etag.py source_path chunk_size [expected]

EXAMPLES:

	# just generate the etag

	$ python ./calculate_multipart_etag.py 100meg.file 50
	"67ff3c4020afd26957fe91c1891e362e-2"
	$


	# compare it with one you have already (success)

	$ python ./calculate_multipart_etag.py 100meg.file 50 "67ff3c4020afd26957fe91c1891e362e-2"
	"67ff3c4020afd26957fe91c1891e362e-2"

	# compare it with one you have already (failure)

	$ python ./calculate_multipart_etag.py 100meg.file 50 "1234567890abcdefghijklmnopqrstuv-42"
	Traceback (most recent call last):
	  File "./calculate_multipart_etag.py", line 81, in <module>
	    print(calculate_multipart_etag(source_path,chunk_size,expected))
	  File "./calculate_multipart_etag.py", line 56, in calculate_multipart_etag
	    raise ValueError('new etag %s does not match expected %s' % (new_etag,expected))
	ValueError: new etag "67ff3c4020afd26957fe91c1891e362e-2" does not match expected "1234567890abcdefghijklmnopqrstuv-42"
	$


calculate_multipart_etag's People

Contributors

tlastowka avatar viettralala avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.