Replace more old 'stat' based code

db4
Eduardo Cavazos 2008-03-13 14:10:56 -06:00
parent fc725ce7fa
commit 67562173a4
2 changed files with 9 additions and 8 deletions

View File

@ -86,11 +86,11 @@ SYMBOL: +unknown+
: stat ( path -- directory? permissions length modified ) : stat ( path -- directory? permissions length modified )
normalize-pathname (stat) ; normalize-pathname (stat) ;
: file-length ( path -- n ) stat drop 2nip ; ! : file-length ( path -- n ) stat drop 2nip ;
: file-modified ( path -- n ) stat >r 3drop r> ; : file-modified ( path -- n ) stat >r 3drop r> ;
: file-permissions ( path -- perm ) stat 2drop nip ; ! : file-permissions ( path -- perm ) stat 2drop nip ;
: exists? ( path -- ? ) file-modified >boolean ; : exists? ( path -- ? ) file-modified >boolean ;
@ -219,11 +219,11 @@ M: pathname <=> [ pathname-string ] compare ;
: with-file-reader ( path encoding quot -- ) : with-file-reader ( path encoding quot -- )
>r <file-reader> r> with-stream ; inline >r <file-reader> r> with-stream ; inline
! : file-contents ( path encoding -- str )
! dupd [ file-info file-info-size read ] with-file-reader ;
: file-contents ( path encoding -- str ) : file-contents ( path encoding -- str )
dupd [ file-length read ] with-file-reader ; dupd [ file-info file-info-size read ] with-file-reader ;
! : file-contents ( path encoding -- str )
! dupd [ file-length read ] with-file-reader ;
: with-file-writer ( path encoding quot -- ) : with-file-writer ( path encoding quot -- )
>r <file-writer> r> with-stream ; inline >r <file-writer> r> with-stream ; inline

View File

@ -14,7 +14,8 @@ TUPLE: file-responder root hook special ;
>r unix-1970 r> seconds time+ ; >r unix-1970 r> seconds time+ ;
: file-http-date ( filename -- string ) : file-http-date ( filename -- string )
file-modified unix-time>timestamp timestamp>http-string ; file-info file-info-modified
unix-time>timestamp timestamp>http-string ;
: last-modified-matches? ( filename -- ? ) : last-modified-matches? ( filename -- ? )
file-http-date dup [ file-http-date dup [
@ -31,7 +32,7 @@ TUPLE: file-responder root hook special ;
[ [
<content> <content>
swap swap
[ file-length "content-length" set-header ] [ file-info file-info-size "content-length" set-header ]
[ file-http-date "last-modified" set-header ] [ file-http-date "last-modified" set-header ]
[ '[ , binary <file-reader> stdio get stream-copy ] >>body ] [ '[ , binary <file-reader> stdio get stream-copy ] >>body ]
tri tri