diff --git a/basis/images/bitmap/bitmap.factor b/basis/images/bitmap/bitmap.factor index df31c8d983..71aaf7b4ec 100644 --- a/basis/images/bitmap/bitmap.factor +++ b/basis/images/bitmap/bitmap.factor @@ -363,7 +363,7 @@ ERROR: unsupported-bitmap-file magic ; ! { "PT" [ parse-os2-pointer ] } [ unsupported-bitmap-file ] } case - ] input-throws-on-eof + ] throw-on-eof ] with-input-stream ; : loading-bitmap>bytes ( loading-bitmap -- byte-array ) diff --git a/basis/images/jpeg/jpeg.factor b/basis/images/jpeg/jpeg.factor index 1050f0615d..7da9f6fc09 100644 --- a/basis/images/jpeg/jpeg.factor +++ b/basis/images/jpeg/jpeg.factor @@ -121,15 +121,17 @@ TUPLE: jpeg-color-info : decode-huff-table ( chunk -- ) data>> [ binary ] [ length ] bi limit-stream [ - [ input-stream get stream>> [ count>> ] [ limit>> ] bi < ] [ - read4/4 swap 2 * + - 16 read - dup [ ] [ + ] map-reduce read - binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader - swap jpeg> huff-tables>> set-nth - ] while - ] throws-on-eof ; + [ input-stream get stream>> [ count>> ] [ limit>> ] bi < ] + [ + read4/4 swap 2 * + + 16 read + dup [ ] [ + ] map-reduce read + binary [ [ read [ B{ } ] unless* ] { } map-as ] with-byte-reader + swap jpeg> huff-tables>> set-nth + ] while + ] with-input-stream* + ] stream-throw-on-eof ; : decode-scan ( chunk -- ) data>> diff --git a/basis/images/pbm/pbm.factor b/basis/images/pbm/pbm.factor index 40db85f58d..a6e7edb9e2 100644 --- a/basis/images/pbm/pbm.factor +++ b/basis/images/pbm/pbm.factor @@ -73,7 +73,7 @@ SINGLETON: pbm-image PRIVATE> M: pbm-image stream>image - drop [ [ read-pbm ] input-throws-on-eof ] with-input-stream ; + drop [ [ read-pbm ] throw-on-eof ] with-input-stream ; M: pbm-image image>stream drop { diff --git a/basis/images/pgm/pgm.factor b/basis/images/pgm/pgm.factor index 914bdcdccb..4457c89135 100644 --- a/basis/images/pgm/pgm.factor +++ b/basis/images/pgm/pgm.factor @@ -50,7 +50,7 @@ SINGLETON: pgm-image wide [ ushort-components ] [ ubyte-components ] if >>component-type ; M: pgm-image stream>image - drop [ [ read-pgm ] input-throws-on-eof ] with-input-stream ; + drop [ [ read-pgm ] throw-on-eof ] with-input-stream ; M: pgm-image image>stream drop { diff --git a/basis/images/png/png.factor b/basis/images/png/png.factor index a539eb7a0c..6e8d7a6c1e 100644 --- a/basis/images/png/png.factor +++ b/basis/images/png/png.factor @@ -324,7 +324,7 @@ ERROR: invalid-color-type/bit-depth loading-png ; read-png-header read-png-chunks parse-ihdr-chunk - ] input-throws-on-eof + ] throw-on-eof ] with-input-stream ; M: png-image stream>image diff --git a/basis/images/ppm/ppm.factor b/basis/images/ppm/ppm.factor index 93c36e60a1..454a4b34f5 100755 --- a/basis/images/ppm/ppm.factor +++ b/basis/images/ppm/ppm.factor @@ -47,7 +47,7 @@ SINGLETON: ppm-image ubyte-components >>component-type ; M: ppm-image stream>image - drop [ [ read-ppm ] input-throws-on-eof ] with-input-stream ; + drop [ [ read-ppm ] throw-on-eof ] with-input-stream ; M: ppm-image image>stream drop { diff --git a/basis/images/tga/tga.factor b/basis/images/tga/tga.factor index 3b7a726a1e..efdcbc537c 100644 --- a/basis/images/tga/tga.factor +++ b/basis/images/tga/tga.factor @@ -254,7 +254,7 @@ ERROR: bad-tga-unsupported ; ubyte-components >>component-type ; M: tga-image stream>image - drop [ [ read-tga ] input-throws-on-eof ] with-input-stream ; + drop [ [ read-tga ] throw-on-eof ] with-input-stream ; M: tga-image image>stream drop diff --git a/basis/images/tiff/tiff.factor b/basis/images/tiff/tiff.factor index 3a26cd61d8..e79ed5f07d 100755 --- a/basis/images/tiff/tiff.factor +++ b/basis/images/tiff/tiff.factor @@ -561,6 +561,6 @@ ERROR: unknown-component-order ifd ; ! tiff files can store several images -- we just take the first for now M: tiff-image stream>image ( stream tiff-image -- image ) - drop [ [ load-tiff tiff>image ] input-throws-on-eof ] with-input-stream ; + drop [ [ load-tiff tiff>image ] throw-on-eof ] with-input-stream ; { "tif" "tiff" } [ tiff-image register-image-class ] each diff --git a/basis/io/streams/throwing/throwing-tests.factor b/basis/io/streams/throwing/throwing-tests.factor index 656bf0fb32..1c9e32914b 100644 --- a/basis/io/streams/throwing/throwing-tests.factor +++ b/basis/io/streams/throwing/throwing-tests.factor @@ -1,56 +1,63 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: io io.streams.limited io.streams.string -io.streams.throwing tools.test kernel ; +USING: io io.encodings.utf8 io.files io.streams.string +io.streams.throwing kernel tools.test destructors ; IN: io.streams.throwing.tests -[ "as" ] +[ "asdf" ] [ - "asdf" 2 - [ 6 read-partial ] throws-on-eof + "asdf" [ [ 6 read-partial ] throw-on-eof ] with-string-reader ] unit-test [ - "asdf" 2 - [ contents ] throws-on-eof + "asdf" [ [ 4 read read1 ] throw-on-eof ] with-string-reader ] [ stream-exhausted? ] must-fail-with [ - "asdf" 2 - [ 2 read read1 ] throws-on-eof + [ + "asdf" &dispose [ + [ 4 swap stream-read ] + [ stream-read1 ] bi + ] stream-throw-on-eof + ] with-destructors ] [ stream-exhausted? ] must-fail-with [ - "asdf" 2 - [ 3 read ] throws-on-eof + "asdf" [ [ 5 read ] throw-on-eof ] with-string-reader ] [ stream-exhausted? ] must-fail-with [ - "asdf" 2 - [ 2 read 2 read ] throws-on-eof + "asdf" [ [ 4 read 4 read ] throw-on-eof ] with-string-reader ] [ stream-exhausted? ] must-fail-with -[ - "asdf" 2 - [ contents contents ] throws-on-eof -] [ stream-exhausted? ] must-fail-with +[ "as" "df" ] [ + "asdf" [ [ 2 read ] throw-on-eof 3 read ] with-string-reader +] unit-test + +[ "as" "df\n" ] [ + "vocab:io/streams/throwing/asdf.txt" utf8 [ + [ 2 read ] throw-on-eof 20 read + ] with-file-reader +] unit-test + +[ "asdf" "asdf" ] [ + "asdf" [ + [ 4 read 0 seek-absolute seek-input 4 read ] throw-on-eof + ] with-string-reader +] unit-test [ - "asdf" 2 - [ 1 seek-absolute seek-input 4 read drop ] throws-on-eof + "asdf" [ [ 1 seek-absolute seek-input 4 read drop ] throw-on-eof ] with-string-reader ] [ stream-exhausted? ] must-fail-with [ "asd" CHAR: f ] [ - "asdf" - [ "f" read-until ] throws-on-eof + "asdf" [ [ "f" read-until ] throw-on-eof ] with-string-reader ] unit-test [ - "asdf" - [ "g" read-until ] throws-on-eof + "asdf" [ [ "g" read-until ] throw-on-eof ] with-string-reader ] [ stream-exhausted? ] must-fail-with [ 1 ] [ - "asdf" 2 - [ 1 seek-absolute seek-input tell-input ] throws-on-eof + "asdf" [ [ 1 seek-absolute seek-input tell-input ] throw-on-eof ] with-string-reader ] unit-test diff --git a/basis/io/streams/throwing/throwing.factor b/basis/io/streams/throwing/throwing.factor index 7e21be9c80..f2cdeab4f7 100644 --- a/basis/io/streams/throwing/throwing.factor +++ b/basis/io/streams/throwing/throwing.factor @@ -8,40 +8,40 @@ ERROR: stream-exhausted n stream word ; throws-on-eof +C: throws-on-eof-stream -M: throws-on-eof stream-element-type stream>> stream-element-type ; +M: throws-on-eof-stream stream-element-type stream>> stream-element-type ; -M: throws-on-eof dispose stream>> dispose ; +M: throws-on-eof-stream dispose stream>> dispose ; -M:: throws-on-eof stream-read1 ( stream -- obj ) +M:: throws-on-eof-stream stream-read1 ( stream -- obj ) stream stream>> stream-read1 [ 1 stream \ read1 stream-exhausted ] unless* ; -M:: throws-on-eof stream-read ( n stream -- seq ) +M:: throws-on-eof-stream stream-read ( n stream -- seq ) n stream stream>> stream-read dup length n = [ n stream \ read stream-exhausted ] unless ; -M:: throws-on-eof stream-read-partial ( n stream -- seq ) +M:: throws-on-eof-stream stream-read-partial ( n stream -- seq ) n stream stream>> stream-read-partial [ n stream \ read-partial stream-exhausted ] unless* ; -M: throws-on-eof stream-tell +M: throws-on-eof-stream stream-tell stream>> stream-tell ; -M: throws-on-eof stream-seek +M: throws-on-eof-stream stream-seek stream>> stream-seek ; -M: throws-on-eof stream-read-until +M: throws-on-eof-stream stream-read-until [ stream>> stream-read-until ] [ '[ length _ \ read-until stream-exhausted ] unless* ] bi ; PRIVATE> -: throws-on-eof ( stream quot -- ) - [ ] dip with-input-stream ; inline +: stream-throw-on-eof ( ..a stream quot: ( ..a stream' -- ..b ) -- ..b ) + [ ] dip call ; inline -: input-throws-on-eof ( quot -- ) - [ input-stream get ] dip with-input-stream ; inline +: throw-on-eof ( ..a quot: ( ..a -- ..b ) -- ..b ) + [ input-stream get ] dip with-input-stream* ; inline