You are looking at historical revision 16222 of this page. It may differ significantly from its current revision.

byte-blob

Description

byte-blob is a library of routines for manipulating byte vectors encoded as blobs.

Library Procedures

Predicates

[procedure] (byte-blob? X) => BOOL

Returns #t if the given object is a byte-blob, #f otherwise.

[procedure] (byte-blob-empty? BYTE-BLOB) => BOOL

Returns #t if the given byte-blob is empty, #f otherwise.

Constructors

[procedure] (byte-blob-empty) => BYTE-BLOB

Returns an empty byte-blob.

[procedure] (byte-blob-replicate N V) => BYTE-BLOB

Returns a byte-blob of length N, where each element is V.

[procedure] (byte-blob-cons X BYTE-BLOB) => BYTE-BLOB

Analogous to list cons, but of complexity O(N), as it requires copying the elements of the byte-blob argument.

[procedure] (list->byte-blob LIST) => BYTE-BLOB

Returns a byte-blob containing the elements of LIST.

[procedure] (string->byte-blob STRING) => BYTE-BLOB

Returns a byte-blob containing the elements of STRING.

Accessors

<procedure(byte-blob-length BYTE-BLOB) => INTEGER</procedure>

Returns the number of elements contained in the given byte-blob.

[procedure] (byte-blob-car BYTE-BLOB) => X

Returns the first element of a byte-blob. The argument byte-blob must be non-empty, or an exception will be thrown.

[procedure] (byte-blob-cdr BYTE-BLOB) => BYTE-BLOB

Returns a byte-blob that contains the elements after the first element of the given byte-blob. The argument byte-blob must be non-empty, or an exception will be thrown.

Transformers

[procedure] (byte-blob-append BYTE-BLOB BYTE-BLOB) => BYTE-BLOB

Appends two byte-blobs together.

[procedure] (byte-blob-reverse BYTE-BLOB) => BYTE-BLOB

Returns a byte-blob that contains the elements of the given byte-blob in reverse order.

[procedure] (byte-blob-intersperse BYTE-BLOB BYTE) => BYTE-BLOB

Returns a byte-blob with the given byte placed between the elements of the given byte-blob.

[procedure] (byte-blob-map F BYTE-BLOB) => BYTE-BLOB

Returns a byte-blob obtained by applying F to each element of the given byte-blob.

[procedure] (byte-blob->list BYTE-BLOB) => LIST

Returns a list containing the elements of the given byte-blob.

[procedure] (byte-blob->string BYTE-BLOB) => STRING

Returns a string containing the elements of the given byte-blob.

Subsequences

[procedure] (byte-blob-take BYTE-BLOB N) => BYTE-BLOB

Returns the prefix of the given byte-blob of length N.

[procedure] (byte-blob-drop BYTE-BLOB N) => BYTE-BLOB

Returns the suffix of the given byte-blob after the first N elements.

[procedure] (byte-blob-span BYTE-BLOB START END) => BYTE-BLOB

Returns the subsequence of the give byte-blob from position START to position END.

Fold

[procedure] (byte-blob-fold-left F INIT BYTE-BLOB) => VALUE
[procedure] (byte-blob-fold-right F INIT BYTE-BLOB) => VALUE

Given a procedure of two arguments, a starting value, and a byte-blob, reduces the byte-blob using the supplied procedure, from left to right, or right to left, respectively.

Find

[procedure] (byte-blob-find NEEDLE HAYSTACK) => LIST

Finds all non-overlapping instances of the byte-blob NEEDLE in the byte-blob 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.

I/O

[procedure] (byte-blob-read PORT N) => BYTE-BLOB

Reads a byte-blob of length N from the given port.

[procedure] (byte-blob-write PORT BYTE-BLOB) => UNDEFINED

Writes the given byte-blob to the given port.

SRFI-4 transformers

[procedure] (u8vector->byte-blob U8VECTOR) => BYTE-BLOB
[procedure] (s8vector->byte-blob S8VECTOR) => BYTE-BLOB
[procedure] (u16vector->byte-blob U16VECTOR) => BYTE-BLOB
[procedure] (s16vector->byte-blob S16VECTOR) => BYTE-BLOB
[procedure] (u32vector->byte-blob U32VECTOR) => BYTE-BLOB
[procedure] (s32vector->byte-blob S32VECTOR) => BYTE-BLOB
[procedure] (f32vector->byte-blob F32VECTOR) => BYTE-BLOB
[procedure] (f64vector->byte-blob F64VECTOR) => BYTE-BLOB
[procedure] (byte-blob->u8vector BYTE-BLOB) => U8VECTOR
[procedure] (byte-blob->s8vector BYTE-BLOB) => S8VECTOR
[procedure] (byte-blob->u16vector BYTE-BLOB) => U16VECTOR
[procedure] (byte-blob->s16vector BYTE-BLOB) => S16VECTOR
[procedure] (byte-blob->u32vector BYTE-BLOB) => U32VECTOR
[procedure] (byte-blob->s32vector BYTE-BLOB) => S32VECTOR
[procedure] (byte-blob->f32vector BYTE-BLOB) => F32VECTOR
[procedure] (byte-blob->f64vector BYTE-BLOB) => F64VECTOR

Version History

License

Based on ideas from the Haskell bytestring library.

The code for byte-blob-find is based on code from the Haskell Text library by Tom Harper and Bryan O'Sullivan.

 Copyright 2009 Ivan Raikov.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
 
 Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 
 Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 
 Neither the name of the author nor the names of its contributors may
 be used to endorse or promote products derived from this software
 without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.