chickadee » byte-blob

byte-blob

Description

byte-blob aims to provide a SRFI-1-inspired API for manipulating byte vectors encoded as blobs. In addition it borrows inspiration from the Haskell bytestring library.

Library Procedures

Predicates

byte-blob? Xprocedure

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

byte-blob-empty? BYTE-BLOBprocedure

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

Constructors

byte-blob-emptyprocedure

Returns an empty byte-blob.

byte-blob-replicate N Vprocedure

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

byte-blob-cons X BYTE-BLOBprocedure

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

blob->byte-blob BLOBprocedure

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

list->byte-blob LISTprocedure

Returns a byte-blob containing the elements of LIST.

string->byte-blob STRINGprocedure

Returns a byte-blob containing the elements of STRING.

Accessors

byte-blob-length BYTE-BLOBprocedure

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

byte-blob-car BYTE-BLOBprocedure

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

byte-blob-cdr BYTE-BLOBprocedure

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.

byte-blob-ref BYTE-BLOB Iprocedure

Returns the i-th element of the given byte-blob as a signed byte.

byte-blob-uref BYTE-BLOB Iprocedure

Returns the i-th element of the given byte-blob as an unsigned byte.

Transformers

byte-blob-set! BYTE-BLOB I Vprocedure

Sets the i-th element of the given byte-blob to the signed byte V.

byte-blob-uset! BYTE-BLOB I Vprocedure

Sets the i-th element of the given byte-blob to the unsigned byte V.

byte-blob-append BYTE-BLOB BYTE-BLOBprocedure

Appends two byte-blobs together.

byte-blob-reverse BYTE-BLOBprocedure

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

byte-blob-intersperse BYTE-BLOB BYTEprocedure

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

byte-blob-map F BYTE-BLOBprocedure

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

byte-blob->blob BYTE-BLOBprocedure

Returns the underlying Scheme blob object.

byte-blob->list BYTE-BLOB #!optional Fprocedure

Returns a list containing the elements of the given byte-blob. If procedure F is provided as a second argument, it is applied to every element of the returned list.

byte-blob->string BYTE-BLOBprocedure

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

Subsequences

byte-blob-take BYTE-BLOB Nprocedure

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

byte-blob-drop BYTE-BLOB Nprocedure

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

byte-blob-span BYTE-BLOB START ENDprocedure

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

Fold

byte-blob-fold-left F INIT BYTE-BLOBprocedure
byte-blob-fold-right F INIT BYTE-BLOBprocedure

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

byte-blob-find NEEDLE HAYSTACKprocedure

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

file->byte-blob FILENAME #!optional MODEprocedure

Returns a byte-blob with the contents of the given file.

MODE is an optional argument that can be one of #:text or #:binary to specify text or binary mode on Windows.

byte-blob-read PORT Nprocedure

Reads a byte-blob of length N from the given port. Currently, the port must support the port->fileno procedure, which means that string ports are not supported.

byte-blob-write PORT BYTE-BLOBprocedure

Writes the given byte-blob to the given port. Currently, the port must support the port->fileno procedure, which means that string ports are not supported.

SRFI-4 transformers

u8vector->byte-blob U8VECTORprocedure
s8vector->byte-blob S8VECTORprocedure
u16vector->byte-blob U16VECTORprocedure
s16vector->byte-blob S16VECTORprocedure
u32vector->byte-blob U32VECTORprocedure
s32vector->byte-blob S32VECTORprocedure
f32vector->byte-blob F32VECTORprocedure
f64vector->byte-blob F64VECTORprocedure
byte-blob->u8vector BYTE-BLOBprocedure
byte-blob->s8vector BYTE-BLOBprocedure
byte-blob->u16vector BYTE-BLOBprocedure
byte-blob->s16vector BYTE-BLOBprocedure
byte-blob->u32vector BYTE-BLOBprocedure
byte-blob->s32vector BYTE-BLOBprocedure
byte-blob->f32vector BYTE-BLOBprocedure
byte-blob->f64vector BYTE-BLOBprocedure

Repository

https://github.com/iraikov/chicken-byte-blob

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-2018 Ivan Raikov
 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/>.

Contents »