: with-file-writer ( path quot -- )
>r <file-writer> r> with-stream ; inline
-: with-file-appender ( path quot -- )
+: with-file-appender ( path encoding quot -- )
>r <file-appender> r> with-stream ; inline
+
+ : temp-directory ( -- path )
+ "temp" resource-path
+ dup exists? not
+ [ dup make-directory ]
+ when ;
+
+ : temp-file ( name -- path ) temp-directory swap path+ ;
IN: temporary
[ "hello world" ] [
- "test.txt" resource-path ascii [
- "test.txt" temp-file [
++ "test.txt" temp-file ascii [
"hello world" write
] with-file-writer
: stdout-handle 12 getenv ;
: stderr-handle 38 getenv ;
-M: object init-stdio
- stdin-handle stdout-handle <duplex-c-stream> stdio set-global
- stderr-handle <c-writer> <plain-writer> stderr set-global ;
+M: object (init-stdio)
+ stdin-handle <c-reader>
+ stdout-handle <c-writer>
+ stderr-handle <c-writer> ;
- M: object io-multiplex (sleep) ;
+ M: object io-multiplex 60 60 * 1000 * or (sleep) ;
-M: object <file-reader>
- "rb" fopen <c-reader> <line-reader> ;
+M: object (file-reader)
+ "rb" fopen <c-reader> ;
-M: object <file-writer>
- "wb" fopen <c-writer> <plain-writer> ;
+M: object (file-writer)
+ "wb" fopen <c-writer> ;
-M: object <file-appender>
- "ab" fopen <c-writer> <plain-writer> ;
+M: object (file-appender)
+ "ab" fopen <c-writer> ;
: show ( msg -- )
#! A word which directly calls primitives. It is used to
] with-scope ;
: mandel-main ( -- )
- "mandel.ppm" resource-path
+ "mandel.ppm" temp-file
- [ mandel write ] with-file-writer ;
+ binary [ mandel write ] with-file-writer ;
MAIN: mandel-main
] "" make ;
: raytracer-main
- "raytracer.pnm" resource-path
+ "raytracer.pnm" temp-file
- [ run write ] with-file-writer ;
+ binary [ run write ] with-file-writer ;
MAIN: raytracer-main
! See http://factorcode.org/license.txt for BSD license.
USING: assocs http kernel math math.parser namespaces sequences
io io.sockets io.streams.string io.files io.timeouts strings
- splitting continuations assocs.lib io.encodings.binary ;
-splitting continuations assocs.lib calendar ;
++splitting calendar continuations assocs.lib io.encodings.binary ;
IN: http.client
: parse-host ( url -- host port )
M: port port-flush ( port -- )
dup buffer-empty? [ drop ] [ (wait-to-write) ] if ;
- M: unix-io io-multiplex ( ms -- )
+ M: unix-io io-multiplex ( ms/f -- )
mx get-global wait-for-events ;
-M: unix-io init-stdio ( -- )
- 0 1 handle>duplex-stream io:stdio set-global
- 2 <writer> io:stderr set-global ;
+M: unix-io (init-stdio) ( -- )
+ 0 <reader>
+ 1 <writer>
+ 2 <writer> ;
! mx io-task for embedding an fd-based mx inside another mx
TUPLE: mx-port mx ;