Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
byte-blob-stream
Description
byte-blob-stream is a library of routines for manipulating byte blobs contained in SRFI-41 streams.
Library Procedures
Predicates
[procedure] (byte-blob-stream? X) => BOOLReturns #t if the given object is a stream that is either empty or its first element is a byte blob, #f otherwise.
[procedure] (byte-blob-stream-empty? STREAM) => BOOLReturns #t if the given stream is empty, #f otherwise.
Constructors
[procedure] (byte-blob-stream-empty) => STREAMReturns an empty stream.
[procedure] (byte-blob-stream-cons BYTE-BLOB STREAM) => STREAMPrepends the given byte blob to the given stream and returns the resulting stream.
Accessors
[procedure] (byte-blob-stream-length STREAM) => INTEGERReturns the number of elements contained in all byte blobs in the given stream.
[procedure] (byte-blob-stream-car STREAM) => XReturns the first element of the first byte blob contained in the given stream. The stream argument must be non-empty, or an exception will be thrown.
[procedure] (byte-blob-stream-cdr STREAM) => STREAMReturns a stream that contains the elements after the first element of the given byte blob. The argument stream must be non-empty, or an exception will be thrown.
[procedure] (byte-blob-stream-ref STREAM I) => BYTEReturns the i-th element of the given stream of byte blobs.
Transformers
[procedure] (byte-blob-stream-append STREAM STREAM) => STREAMAppends two streams of byte blobs together.
[procedure] (byte-blob-stream-reverse STREAM) => STREAMReturns a stream that contains the elements of the given stream of byte blobs in reverse order.
[procedure] (byte-blob-stream-intersperse STREAM BYTE) => STREAMReturns a stream of byte blobs with the given byte placed between the elements of the each byte blob from the input stream, and between byte blobs.
[procedure] (byte-blob-stream-map F STREAM) => STREAMReturns a stream of byte blobs obtained by applying F to each element of the byte blobs in the input stream.
[procedure] (byte-blob-stream->list STREAM) => LISTReturns a list containing the elements of the byte blobs contained in the input stream. If procedure F is provided as a second argument, it is applied to every element of the returned list.
[procedure] (list->byte-blob-stream LIST) => STREAMReturns a stream of a single byte blob containing the elements of the given list.
Subsequences
[procedure] (byte-blob-stream-take STREAM N) => STREAMReturns the prefix of the given stream of byte blobs of length N.
[procedure] (byte-blob-stream-drop STREAM N) => STREAMReturns the suffix of the given stream of byte blobs after the first N elements.
[procedure] (byte-blob-stream-span STREAM START END) => STREAMReturns the subsequence of the given stream of byte blobs from position START to position END.
Fold
[procedure] (byte-blob-stream-fold-left F INIT STREAM) => VALUE[procedure] (byte-blob-stream-fold-right F INIT STREAM) => VALUE
Given a procedure of two arguments, a starting value, and a stream of byte blobs, reduces the stream using the supplied procedure, from left to right, or right to left, respectively.
Find
[procedure] (byte-blob-stream-find NEEDLE HAYSTACK) => LISTFinds all non-overlapping instances of the byte blob NEEDLE in the stream of byte blobs HAYSTACK. The first element of the returned list is the prefix of HAYSTACK prior to any matches of NEEDLE. The second is a list of lists.
The first element of each pair in the list is a span from the beginning of a match to the beginning of the next match, while the second is a span from the beginning of the match to the end of the input.
Files
[procedure] (file->byte-blob-stream FILENAME [BLOCKSIZE] ) => STREAMReads a file into a byte-blob stream.
Version History
- 1.5 Updated test script to return proper exit code
- 1.4 Added procedure list->byte-blob-stream
- 1.3 Added optional second argument to byte-blob-stream->list
- 1.2 Added procedure file->byte-blob-stream
- 1.0 Initial release
License
Based on ideas from the Haskell bytestring library.
The code for byte-blob-stream-find is based on code from the Haskell Text library by Tom Harper and Bryan O'Sullivan.
Copyright 2009-2011 Ivan Raikov and the Okinawa Institute of Science and Technology.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.