]> gitweb.factorcode.org Git - factor.git/commitdiff
http.client: adding version of download-to that checks file exists.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 9 Jun 2014 15:57:45 +0000 (08:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 9 Jun 2014 15:57:45 +0000 (08:57 -0700)
basis/http/client/client-docs.factor
basis/http/client/client.factor

index 77aa293dac0c4651ae3317c2cd8f4eb04e79a1b6..3628f9942b94d3de93fa0938b7c12c37b8273aec 100644 (file)
@@ -50,6 +50,11 @@ HELP: download-to
 { $description "Downloads the contents of the URL to a file with the given pathname." }
 { $errors "Throws an error if the HTTP request fails." } ;
 
+HELP: ?download-to
+{ $values { "url" "a " { $link url } " or " { $link string } } { "file" "a pathname string" } }
+{ $description "Version of " { $link download-to } " that only downloads if " { $snippet "file" } " does not exist." }
+{ $errors "Throws an error if the HTTP request fails." } ;
+
 HELP: http-get
 { $values { "url" "a " { $link url } " or " { $link string } } { "response" response } { "data" sequence } }
 { $description "Downloads the contents of a URL." }
@@ -156,6 +161,7 @@ ARTICLE: "http.client.get" "GET requests with the HTTP client"
 { $subsections
     download
     download-to
+    ?download-to
 }
 "Advanced usage involves constructing a " { $link request } ", which allows " { $link "http.cookies" } " and " { $link "http.headers" } " to be set:"
 { $subsections
index 7f7d5bd3791cbbdd5c8d055880c160782cd20d7f..0edcacb7b199d4bd7a202149956b18d65821d601 100644 (file)
@@ -188,6 +188,9 @@ ERROR: download-failed response ;
         <get-request> [ write ] with-http-request drop
     ] with-file-writer ;
 
+: ?download-to ( url file -- )
+    dup exists? [ 2drop ] [ download-to ] if ;
+
 : download ( url -- )
     dup download-name download-to ;