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.
TOC »
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
Version History
- 1.18 Added optional mode argument to file->byte-blob (thanks to dthedens)
- 1.17 Added documentation for byte-blob->blob procedure (reported by retroj)
- 1.16 Remove files created by unit tests (thanks to mario)
- 1.15 Fixes for issues #1037 and #1038 (thanks to dthedens)
- 1.14 Bug fix in byte-blob-find
- 1.13 Added byte-blob-uref and byte-blob-uset! (thanks to Panos Stergiotis)
- 1.12 Fixed a bug in byte-blob-drop; added byte-blob-set! (thanks to Panos Stergiotis)
- 1.11 Updated test script to return proper exit code
- 1.9 Bug fix in byte-blob-find
- 1.8 Changed (import posix) to (require-extension posix)
- 1.7 Bug fix in byte-blob->string
- 1.6 Added optional second argument to byte-blob->list
- 1.5 Bug fixes in byte-blob-read and byte-blob-write
- 1.4 Added procedure blob->byte-blob
- 1.3 Fix in invocation of chicken_Panic
- 1.2 Added procedure byte-blob-ref
- 1.0 Initial release
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-2015 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/>.