2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								! Copyright (C) 2009 Doug Coleman. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								! See http://factorcode.org/license.txt for BSD license. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								USING:  help.markup  help.syntax  kernel  math  io  ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								IN:  io.streams.limited 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  <limited-stream> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     { "stream"  "an input stream"  } { "limit"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								     { "stream'"  "an input stream"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $description "Constructs a new "  { $link limited-stream } " from an existing stream. User code should use "  { $link limit-stream } " or "  { $link limited-input } "."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 16:42:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								HELP:  limit-stream 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 16:42:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     { "stream"  "an input stream"  } { "limit"  integer  }
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 16:42:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								     { "stream'"  "a stream"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Changes a decoder's stream to be a limited stream, or wraps "  { $snippet "stream"  } " in a "  { $link limited-stream } "."  }
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $examples
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    "Limiting a longer stream to length three:" 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    { $example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "USING: accessors continuations io io.streams.limited" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "io.streams.string kernel prettyprint ;" 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        "\"123456\" <string-reader> 3 limit-stream" 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        "100 swap stream-read ." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        "\"123\"" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								HELP:  limited-stream 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $values
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { "value"  "a limited-stream class"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 16:42:41 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $description "Limited streams wrap other streams, changing their behavior to throw an exception or return "  { $link f  } " upon exhaustion."  } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								HELP:  limited-input 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ $values { "limit"  integer  } }
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ $description "Wraps the current "  { $link input-stream  } " in a "  { $link limited-stream } "."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ARTICLE: "io.streams.limited"  "Limited input streams" 
							 
						 
					
						
							
								
									
										
										
										
											2010-09-27 21:20:48 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"The "  { $vocab-link "io.streams.limited"  } " vocabulary wraps a stream to behave as if it had only a limited number of bytes. Limiting a seekable stream creates a window of bytes that supports seeking and re-reading of bytes in that window. If it is desirable for a stream to throw an exception upon exhaustion, use the "  { $vocab-link "io.streams.throwing"  } " vocabulary in conjunction with this one."  $nl
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								"Wrap a stream in a limited stream:" 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 14:30:57 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $subsections limited-stream }
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								"Wrap the current "  { $link input-stream  } " in a limited stream:" 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-09 16:52:15 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ $subsections limited-input } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-20 14:21:58 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ABOUT: "io.streams.limited"