]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/files/unique/unique.factor
io.files.unique: add a word that opens a temp file and gives you a write stream
[factor.git] / basis / io / files / unique / unique.factor
index e5bdc599c8915c9e19166f626f1a26f7d25bb9dc..0b3c59768ab0abf0174ddd6267e37832a21e25ab 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: combinators continuations fry io.backend io.directories
-io.pathnames kernel locals namespaces random.data sequences
-system vocabs ;
+io.files io.pathnames kernel locals namespaces random.data
+sequences system vocabs ;
 IN: io.files.unique
 
 <PRIVATE
@@ -25,6 +25,9 @@ SYMBOL: unique-retries
 : random-file-name ( -- string )
     unique-length get random-string ;
 
+: random-file-name* ( prefix suffix -- string )
+    unique-length get random-string glue ;
+
 : retry ( quot: ( -- ? ) n -- )
     <iota> swap [ drop ] prepose attempt-all ; inline
 
@@ -48,6 +51,9 @@ PRIVATE>
         ] recover
     ] unique-retries get retry [ absolute-path ] map ;
 
+: with-unique-file-writer ( ..a prefix suffix encoding quot -- ..b path )
+    [ random-file-name* ] 2dip [ with-file-writer-secure ] keepdd normalize-path ; inline
+
 :: cleanup-unique-file ( ..a prefix suffix quot: ( ..a path -- ..b ) -- ..b )
     prefix suffix unique-file :> path
     [ path quot call ] [ path delete-file ] finally ; inline