From ca315e79967133ab69556401bc5247afac2db476 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Thu, 25 Oct 2012 21:40:43 -0700 Subject: [PATCH] io.random: adding "random-file". --- extra/io/random/random.factor | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/extra/io/random/random.factor b/extra/io/random/random.factor index 47abdec2ed..3055919641 100644 --- a/extra/io/random/random.factor +++ b/extra/io/random/random.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2012 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: combinators fry io kernel locals math math.order random -sequences sequences.private ; +USING: combinators destructors fry io io.encodings.binary +io.files io.streams.limited io.streams.random kernel locals +math math.order random sequences sequences.private ; IN: io.random @@ -26,3 +27,10 @@ PRIVATE> r n < [ line r accum set-nth-unsafe ] when ] if ] each-numbered-line accum ; + +: random-file ( n path -- ) + [ + [ swap limit-stream ] + [ binary ] bi* + [ &dispose ] bi@ stream-copy + ] with-destructors ;