Commit f4a706b7 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add --get-filesize option and url_get_size() function

parent 63f72b9d
...@@ -370,6 +370,7 @@ GETRESPONSE='' ...@@ -370,6 +370,7 @@ GETRESPONSE=''
GETFILENAME='' GETFILENAME=''
GETREALURL='' GETREALURL=''
GETIPFSCID='' GETIPFSCID=''
GETFILESIZE=''
LATEST='' LATEST=''
SECONDLATEST='' SECONDLATEST=''
CHECKMIRRORS='' CHECKMIRRORS=''
...@@ -446,6 +447,7 @@ Options: ...@@ -446,6 +447,7 @@ Options:
--check-site URL - check if the site is accessible (returns HTTP 200 OK or 404 Not found) --check-site URL - check if the site is accessible (returns HTTP 200 OK or 404 Not found)
--get-response URL - get response with all headers (ever if HEAD is not acceptable) --get-response URL - get response with all headers (ever if HEAD is not acceptable)
--get-filename URL - print filename for the URL (via Content-Disposition if applicable) --get-filename URL - print filename for the URL (via Content-Disposition if applicable)
--get-filesize URL - print file size in bytes (via Content-Length)
--get-real-url URL - print URL after all redirects --get-real-url URL - print URL after all redirects
--get-ipfs-cid URL - print CID for URL (after all redirects) --get-ipfs-cid URL - print CID for URL (after all redirects)
...@@ -570,6 +572,9 @@ while [ -n "$1" ] ; do ...@@ -570,6 +572,9 @@ while [ -n "$1" ] ; do
--get-ipfs-cid) --get-ipfs-cid)
GETIPFSCID="$1" GETIPFSCID="$1"
;; ;;
--get-filesize)
GETFILESIZE="$1"
;;
--latest) --latest)
LATEST="$1" LATEST="$1"
;; ;;
...@@ -1734,6 +1739,11 @@ url_get_header() ...@@ -1734,6 +1739,11 @@ url_get_header()
url_get_headers "$URL" | grep -i "^ *$HEADER: " | sed -e "s|^ *$HEADER: ||i" url_get_headers "$URL" | grep -i "^ *$HEADER: " | sed -e "s|^ *$HEADER: ||i"
} }
url_get_size()
{
url_get_header "$1" "Content-Length" | tr -d '\r'
}
url_get_raw_real_url() url_get_raw_real_url()
{ {
local URL="$1" local URL="$1"
...@@ -1878,6 +1888,11 @@ sget() ...@@ -1878,6 +1888,11 @@ sget()
exit exit
fi fi
if [ -n "$GETFILESIZE" ] ; then
url_get_size "$URL"
exit
fi
local REALURL="$(get_real_url "$URL")" || return local REALURL="$(get_real_url "$URL")" || return
if [ -n "$GETREALURL" ] ; then if [ -n "$GETREALURL" ] ; then
...@@ -2032,6 +2047,11 @@ sget() ...@@ -2032,6 +2047,11 @@ sget()
exit exit
fi fi
if [ -n "$GETFILESIZE" ] ; then
url_get_size "$URL"
exit
fi
if [ -n "$GETREALURL" ] ; then if [ -n "$GETREALURL" ] ; then
get_real_url "$URL" get_real_url "$URL"
exit exit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment