From 90b962bbd3ba7511eca87ec6c018cbfc31f6511b Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Fri, 9 Jul 2010 14:26:01 -0700 Subject: [PATCH] io.streams.throwing: implement read-until --- basis/io/streams/throwing/throwing-tests.factor | 10 ++++++++++ basis/io/streams/throwing/throwing.factor | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/basis/io/streams/throwing/throwing-tests.factor b/basis/io/streams/throwing/throwing-tests.factor index 1e7cc1cd2b..656bf0fb32 100644 --- a/basis/io/streams/throwing/throwing-tests.factor +++ b/basis/io/streams/throwing/throwing-tests.factor @@ -40,6 +40,16 @@ IN: io.streams.throwing.tests [ 1 seek-absolute seek-input 4 read drop ] throws-on-eof ] [ stream-exhausted? ] must-fail-with +[ "asd" CHAR: f ] [ + "asdf" + [ "f" read-until ] throws-on-eof +] unit-test + +[ + "asdf" + [ "g" read-until ] throws-on-eof +] [ stream-exhausted? ] must-fail-with + [ 1 ] [ "asdf" 2 [ 1 seek-absolute seek-input tell-input ] throws-on-eof diff --git a/basis/io/streams/throwing/throwing.factor b/basis/io/streams/throwing/throwing.factor index bc9adc66bf..7e21be9c80 100644 --- a/basis/io/streams/throwing/throwing.factor +++ b/basis/io/streams/throwing/throwing.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors destructors io kernel locals namespaces -sequences ; +sequences fry ; IN: io.streams.throwing ERROR: stream-exhausted n stream word ; @@ -34,6 +34,10 @@ M: throws-on-eof stream-tell M: throws-on-eof stream-seek stream>> stream-seek ; +M: throws-on-eof stream-read-until + [ stream>> stream-read-until ] + [ '[ length _ \ read-until stream-exhausted ] unless* ] bi ; + PRIVATE> : throws-on-eof ( stream quot -- )