]> gitweb.factorcode.org Git - factor.git/commitdiff
http.download: ?download-to -> download-to-once
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 25 Mar 2024 04:46:53 +0000 (23:46 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 25 Mar 2024 04:51:14 +0000 (23:51 -0500)
Hopefully better name for a word that caches the download instead
of downloading every time.

18 files changed:
basis/fixups/fixups.factor
basis/http/download/download-docs.factor
basis/http/download/download.factor
basis/unicode/breaks/breaks-tests.factor
basis/unicode/collation/collation-tests.factor
basis/unicode/normalize/normalize-tests.factor
extra/bunny/model/model.factor
extra/geo-ip/geo-ip.factor
extra/gpu/demos/bunny/bunny.factor
extra/macho/macho-tests.factor
extra/project-euler/098/098.factor
extra/rosetta-code/anagrams-deranged/anagrams-deranged.factor
extra/rosetta-code/ordered-words/ordered-words.factor
extra/rosetta-code/text-processing/max-licenses/max-licenses.factor
extra/scryfall/scryfall.factor
extra/spelling/spelling.factor
extra/tldr/tldr.factor
extra/youtube/youtube.factor

index abe96e3f905badfaf88c19507e2d23878db0b51d..9ec5d6b285719462761a1d93f70a11de00e1b53c 100644 (file)
@@ -74,6 +74,7 @@ CONSTANT: word-renames {
     { "assoc-all-value?" { "all-values?" "0.100" } }
     { "assoc-any-key?" { "any-key?" "0.100" } }
     { "assoc-any-value?" { "any-value?" "0.100" } }
+    { "?download-to" { "download-once-to" "0.100" } }
 }
 
 : compute-assoc-fixups ( continuation name assoc -- seq )
index 72dc7b2d9d69dab6f053b57703f7b16c7624f898..76f3a19dc07a7edaa08d4934fc53c2cb7a8e79a4 100644 (file)
@@ -7,11 +7,19 @@ IN: http.download
 HELP: download
 { $values { "url" { $or url string } } { "path" "a pathname string" } }
 { $description "Downloads the contents of the URL to a file in the " { $link current-directory } " having the same file name and returns the pathname." }
+{ $notes "Use this to download the file every time." }
 { $errors "Throws an error if the HTTP request fails." } ;
 
 HELP: download-to
 { $values { "url" { $or url string } } { "file" "a pathname string" } { "path" "a pathname string" } }
 { $description "Downloads the contents of the URL to a file with the given pathname and returns the pathname." }
+{ $notes "Use this to download the file every time." }
+{ $errors "Throws an error if the HTTP request fails." } ;
+
+HELP: download-once-to
+{ $values { "url" { $or url string } } { "file" "a pathname string" } { "path" "a pathname string" } }
+{ $description "If the file exists on disk, returns that pathname without downloading anything. Otherwise, downloads the contents of the URL to a file with the given pathname and returns the pathname." }
+{ $notes "Use this if the contents of the URL are not expected to change." }
 { $errors "Throws an error if the HTTP request fails." } ;
 
 
@@ -22,6 +30,7 @@ ARTICLE: "http.download" "HTTP Download Utilities"
 { $subsections
     download
     download-to
+    download-once-to
 }
 ;
 
index 59a71199aceca9f498d253d277a0a37b83e9b52d..1f54064206e2a4fa32c252e22cc8d68044244e34 100644 (file)
@@ -76,16 +76,16 @@ IN: http.download
 : download-temporary-name ( url -- prefix suffix )
     [ "temp." ".temp" ] dip download-name prepend ;
 
-: download-file-to ( url file -- path )
+PRIVATE>
+
+: download-to ( url file -- path )
     [
         [ download-temporary-name binary ] keep
         '[ _ http-write-request ] with-unique-file-writer
     ] dip [ move-file ] keep ;
 
-PRIVATE>
-
-: download-to ( url file -- path )
-    dup file-exists? [ nip ] [ download-file-to ] if ;
+: download-once-to ( url file -- path )
+    dup file-exists? [ nip ] [ download-to ] if ;
 
 : download-outdated-to ( url file duration -- path )
     2dup delete-when-old [ drop download-to ] [ drop nip ] if ;
index 2fef15c601d223d29e2762c192c65a67f4746bbb..801b486ad8ef3d64c071ef314544cab5be47c26f 100644 (file)
@@ -21,11 +21,11 @@ IN: unicode.breaks.tests
 
 : grapheme-break-test ( -- filename )
     "https://downloads.factorcode.org/misc/UCD/15.1.0/auxiliary/GraphemeBreakTest.txt"
-    "GraphemeBreakTest-15.1.0.txt" cache-file download-to ;
+    "GraphemeBreakTest-15.1.0.txt" cache-file download-once-to ;
 
 : word-break-test ( -- filename )
     "https://downloads.factorcode.org/misc/UCD/15.1.0/auxiliary/WordBreakTest.txt"
-    "WordBreakTest-15.1.0.txt" cache-file download-to ;
+    "WordBreakTest-15.1.0.txt" cache-file download-once-to ;
 
 : parse-test-file ( file-name -- tests )
     utf8 file-lines
index 2cf37e1b1ed2a88857f7e08a3167df1326ac4623..6e985c2bab91d424b858aafc432c5642fee8429c 100644 (file)
@@ -19,7 +19,7 @@ IN: unicode.collation.tests
 
 : collation-test-lines ( -- lines )
     "https://downloads.factorcode.org/misc/UCA/15.1.0/CollationTest_SHIFTED.txt"
-    "CollationTest_SHIFTED_15.1.0.txt" cache-file download-to
+    "CollationTest_SHIFTED_15.1.0.txt" cache-file download-once-to
     utf8 file-lines [ "#" head? ] reject harvest ;
 
 : parse-collation-test-shifted ( -- lines )
index 3d72ad99e5852776da317293730dfd667e5a8f10..edfc27dba8af89305d03ddc5a46f0b798d7f7013 100644 (file)
@@ -27,7 +27,7 @@ IN: unicode.normalize.tests
 ! Could use simple-flat-file after some cleanup
 : parse-normalization-tests ( -- tests )
     "https://downloads.factorcode.org/misc/UCD/15.1.0/NormalizationTest.txt"
-    "NormalizationTest-15.1.0.txt" cache-file download-to
+    "NormalizationTest-15.1.0.txt" cache-file download-once-to
     utf8 file-lines [ "#" head? ] reject
     [ "@" head? ] split*-when
     2 <groups> [ first2 [ first ] dip 2array ] map
index fb64d7193d2ee7b57ba1310bfd982b50acbd0e58..dd2003a4c92683e4e16f340f7f8c665f79580495 100644 (file)
@@ -46,7 +46,7 @@ CONSTANT: model-url
 "https://downloads.factorcode.org/misc/bun_zipper.ply"
 
 : download-bunny ( -- path )
-    model-url model-path download-to ;
+    model-url model-path download-once-to ;
 
 :: (draw-triangle) ( ns vs triple -- )
     triple [| elt |
index 890969fca4c41920d58599ab6184cc0dd9519f3f..4e8cfac746658a7dd64a4579b4bd8f9ad416297b 100644 (file)
@@ -12,7 +12,7 @@ CONSTANT: db-url "https://software77.net/geo-ip/?DL=1"
 
 : download-db ( -- path )
     db-path dup file-exists? [
-        db-url over ".gz" append download-to
+        db-url over ".gz" append download-once-to
         { "gunzip" } over ".gz" append absolute-path suffix try-process
     ] unless ;
 
index 97bde0ad8739c1d5381a29a96d375d14619b1a28..f5963e714e89dc848caacd3ff4476ec5b9c4ae84 100644 (file)
@@ -149,7 +149,7 @@ CONSTANT: bunny-model-url
 "https://downloads.factorcode.org/misc/bun_zipper.ply"
 
 : download-bunny ( -- path )
-    bunny-model-url bunny-model-path download-to ;
+    bunny-model-url bunny-model-path download-once-to ;
 
 : get-bunny-data ( bunny-state -- )
     download-bunny bunny-data
index 48626fcaf3630bd62ff429cb0a6de14ffc4250db..5bcfa60378dfffb2b1e533e022a98d502936b8a5 100644 (file)
@@ -24,11 +24,11 @@ STRING: validation-output
 
 : a.macho ( -- path )
     URL" https://downloads.factorcode.org/misc/a.macho"
-    "a.macho" cache-file download-to ;
+    "a.macho" cache-file download-once-to ;
 
 : a2.macho ( -- path )
     URL" https://downloads.factorcode.org/misc/a2.macho"
-    "a2.macho" cache-file download-to ;
+    "a2.macho" cache-file download-once-to ;
 
 cpu ppc? [
     { $ validation-output }
index 27db0b8cf512f340ca7ce4e108fc4c607cce3210..72c332a1f5624cf9c4fd5b267786fd94c5750a4e 100644 (file)
@@ -42,7 +42,7 @@ IN: project-euler.098
 
 : wordlist ( -- seq )
     "https://projecteuler.net/project/resources/p098_words.txt"
-    "p098_words.txt" temp-file download-to
+    "p098_words.txt" temp-file download-once-to
     utf8 file-contents "," split [ rest-slice but-last ] map ;
 
 : squarelist ( n -- seq )
index d65f06a8a99c0d0d4f41317989c169c9200163c2..53db81bb0036624e8eb3f26520aa13643cac6c7e 100644 (file)
@@ -42,7 +42,7 @@ IN: rosettacode.anagrams-deranged
 
 : default-word-list ( -- path )
     URL" https://raw.githubusercontent.com/quinnj/Rosetta-Julia/master/unixdict.txt"
-    "unixdict.txt" temp-file download-to ;
+    "unixdict.txt" temp-file download-once-to ;
 
 : longest-deranged-anagrams ( -- anagrams )
     default-word-list (longest-deranged-anagrams) ;
index 0ce7c4319e0e2872d27c723cb3f6e34f11e9d229..8c37abfc3696542e6316a7294ea01c71874ebdfd 100644 (file)
@@ -19,7 +19,7 @@ IN: rosetta-code.ordered-words
 MEMO: word-list ( -- seq )
     URL" https://raw.githubusercontent.com/quinnj/Rosetta-Julia/master/unixdict.txt"
     "unixdict.txt" temp-file
-    download-to utf8 file-lines ;
+    download-once-to utf8 file-lines ;
 
 : ordered-word? ( word -- ? )
     >lower [ <= ] monotonic? ;
index 9456ea799f397d3d8fffd95b9a6d9503497503c6..238d59675366d71ca188708e42458f78be4efc59 100644 (file)
@@ -62,10 +62,8 @@ TUPLE: maxlicense max-count current-count times ;
 : process ( max line -- max ) split-line inc-current-count update-time ;
 
 MEMO: mlijobs ( -- lines )
-    "mlijobs.txt" temp-file dup file-exists? [
-        URL" https://rosettacode.org/resources/mlijobs.txt"
-        over download-to
-    ] unless ascii file-lines ;
+    URL" https://raw.githubusercontent.com/def-/nim-unsorted/master/mlijobs.txt"
+    "mlijobs.txt" temp-file download-once-to ascii file-lines ;
 
 PRIVATE>
 
index 0e019a507ad5b6fdc46a1c1bf56eeefe36d72b55..58cd66d52db764bd403843e43b8dc415ec27cabc 100644 (file)
@@ -53,7 +53,7 @@ CONSTANT: scryfall-images-path "resource:scryfall-images/"
     ensure-scryfall-images-directory
     normal-images [
         dup scryfall>local dup delete-when-zero-size
-        [ download-to ] [ nip ] if
+        [ download-once-to ] [ nip ] if
     ] map
     [ load-image ] map ;
 
@@ -61,7 +61,7 @@ CONSTANT: scryfall-images-path "resource:scryfall-images/"
     ensure-scryfall-images-directory
     small-images [
         dup scryfall>local dup delete-when-zero-size
-        [ download-to ] [ nip ] if
+        [ download-once-to ] [ nip ] if
     ] map
     [ load-image ] map ;
 
index d48bffdc84ca00ffd987b818cca373039877bbb6..f3c512f9cd2a8eaafeb603eff2a273a4c7065dc9 100644 (file)
@@ -58,7 +58,7 @@ CONSTANT: ALPHABET "abcdefghijklmnopqrstuvwxyz"
 
 MEMO: default-dictionary ( -- counts )
     URL" https://norvig.com/big.txt" "big.txt" temp-file
-    download-to load-dictionary ;
+    download-once-to load-dictionary ;
 
 : (correct) ( word dictionary -- word/f )
     corrections ?first ;
index 5fc08b8af525514b82e55f8103a47e2f5760d90c..47560add8b70734c6363d15a7fdbc3b86c5f07ec 100644 (file)
@@ -26,7 +26,7 @@ CONSTANT: tldr-zip URL" https://tldr-pages.github.io/assets/tldr.zip"
 
 : download-tldr ( -- )
     "tldr" cache-file dup make-directory [
-        tldr-zip "tldr.zip" download-to drop
+        tldr-zip "tldr.zip" download-once-to drop
         { "unzip" "tldr.zip" } try-process
     ] with-directory ;
 
index 6d1d549c7f317876584df8a4f8aecd2b5d77f3b4..261165dbb454dd5e056b2e370943d7b8b6b58ab1 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2013 John Benediktsson
 ! See https://factorcode.org/license.txt for BSD license
 
-USING: assocs http.client kernel make math.order sequences
-splitting urls urls.encoding ;
+USING: assocs http.client http.download kernel math.order
+sequences splitting urls urls.encoding ;
 
 IN: youtube
 
@@ -66,12 +66,12 @@ CONSTANT: video-info-url URL" https://www.youtube.com/get_video_info"
 : downloadable? ( video-info -- ? )
     "use_cipher_signature" of "False" = ;
 
-: download-video ( video-id -- )
+: download-video ( video-id -- path )
     get-video-info [
         downloadable? [ "Video is encrypted." throw ] unless
     ] [
         video-formats [ "type" of "video/mp4" head? ] find nip
         video-download-url
     ] [
-        "title" of sanitize ".mp4" append download-to
+        "title" of sanitize ".mp4" append download-once-to
     ] tri ;