chickadee » byte-blob-stream

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 is a library of routines for manipulating byte blobs contained in SRFI-41 streams.

Library Procedures


byte-blob-stream? Xprocedure

Returns #t if the given object is a stream that is either empty or its first element is a byte blob, #f otherwise.

byte-blob-stream-empty? STREAMprocedure

Returns #t if the given stream is empty, #f otherwise.



Returns an empty stream.

byte-blob-stream-cons BYTE-BLOB STREAMprocedure

Prepends the given byte blob to the given stream and returns the resulting stream.


byte-blob-stream-length STREAMprocedure

Returns the number of elements contained in all byte blobs in the given stream.

byte-blob-stream-car STREAMprocedure

Returns 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.

byte-blob-stream-cdr STREAMprocedure

Returns 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.

byte-blob-stream-ref STREAM Iprocedure

Returns the i-th element of the given stream of byte blobs.


byte-blob-stream-append STREAM STREAMprocedure

Appends two streams of byte blobs together.

byte-blob-stream-reverse STREAMprocedure

Returns a stream that contains the elements of the given stream of byte blobs in reverse order.

byte-blob-stream-intersperse STREAM BYTEprocedure

Returns 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.

byte-blob-stream-map F STREAMprocedure

Returns a stream of byte blobs obtained by applying F to each element of the byte blobs in the input stream.

byte-blob-stream->list STREAMprocedure

Returns 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.

list->byte-blob-stream LISTprocedure

Returns a stream of a single byte blob containing the elements of the given list.


byte-blob-stream-take STREAM Nprocedure

Returns the prefix of the given stream of byte blobs of length N.

byte-blob-stream-drop STREAM Nprocedure

Returns the suffix of the given stream of byte blobs after the first N elements.

byte-blob-stream-span STREAM START ENDprocedure

Returns the subsequence of the given stream of byte blobs from position START to position END.


byte-blob-stream-fold-left F INIT STREAMprocedure
byte-blob-stream-fold-right F INIT STREAMprocedure

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.


byte-blob-stream-find NEEDLE HAYSTACKprocedure

Finds 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.


file->byte-blob-stream FILENAME #!optional BLOCKSIZEprocedure

Reads a file into a byte-blob stream.

Version History


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
 General Public License for more details.
 A full copy of the GPL license can be found at

Contents »