Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the size of a remote ruby gem?

Tags:

ruby

rubygems

I was installing the libv8 gem (which is ~512M) from rubygems and wondered why it was taking so long. This...

gem specification -r libv8

... gave me nothing about the size of the gem. Then I looked in the docs, and it looks like the gem creator has the option of putting information about the size of their gem under one of rubygems's pre-defined "optional gemspec attributes".

Q: So one can't reliably know the size of a remote gem before one installs it?

Bonus question: Would it be impractical to make gem size a required gemspec attribute?

like image 740
eeeeeean Avatar asked Sep 11 '25 23:09

eeeeeean


1 Answers

Here is a terrible way to do it on OS X or Linux:

curl -s  https://rubygems.org/api/v1/gems/<gem-name>.yaml | sed -n "s/gem_uri: //p" | xargs curl -sLI | grep -i Content-Length | tail -1

will give you the size (in bytes).

explanation:

use curl and the rubygems api to get some info about the gem:

curl -s  https://rubygems.org/api/v1/gems/thor.yaml

get the URL for the gem file download

sed -n "s/gem_uri: //p"

download the response header for the gem (following redirects)

xargs curl -sLI 

show only the last instance of 'Content-Length', case insensitive

grep -i Content-Length | tail -1

result (~82k):

Content-Length: 83456
like image 94
Ryan Horrisberger Avatar answered Sep 13 '25 13:09

Ryan Horrisberger