You are looking at historical revision 39572 of this page. It may differ significantly from its current revision.
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
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
[procedure] (byte-blob? X) => BOOLReturns #t if the given object is a byte-blob, #f otherwise.
[procedure] (byte-blob-empty? BYTE-BLOB) => BOOLReturns #t if the given byte-blob is empty, #f otherwise.
Constructors
[procedure] (byte-blob-empty) => BYTE-BLOBReturns an empty byte-blob.
[procedure] (byte-blob-replicate N V) => BYTE-BLOBReturns a byte-blob of length N, where each element is V.
[procedure] (byte-blob-cons X BYTE-BLOB) => BYTE-BLOBAnalogous to list cons, but of complexity O(N), as it requires copying the elements of the byte-blob argument.
[procedure] (blob->byte-blob BLOB) => BYTE-BLOBReturns a byte-blob containing the elements of the given blob.
[procedure] (list->byte-blob LIST) => BYTE-BLOBReturns a byte-blob containing the elements of LIST.
[procedure] (string->byte-blob STRING) => BYTE-BLOBReturns a byte-blob containing the elements of STRING.
Accessors
[procedure] (byte-blob-length BYTE-BLOB) => INTEGERReturns the number of elements contained in the given byte-blob.
[procedure] (byte-blob-car BYTE-BLOB) => XReturns 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-BLOBReturns 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.
[procedure] (byte-blob-ref BYTE-BLOB I) => BYTEReturns the i-th element of the given byte-blob as a signed byte.
[procedure] (byte-blob-uref BYTE-BLOB I) => BYTEReturns the i-th element of the given byte-blob as an unsigned byte.
Transformers
[procedure] (byte-blob-set! BYTE-BLOB I V) => VOIDSets the i-th element of the given byte-blob to the signed byte V.
[procedure] (byte-blob-uset! BYTE-BLOB I V) => VOIDSets the i-th element of the given byte-blob to the unsigned byte V.
[procedure] (byte-blob-append BYTE-BLOB BYTE-BLOB) => BYTE-BLOBAppends two byte-blobs together.
[procedure] (byte-blob-reverse BYTE-BLOB) => BYTE-BLOBReturns a byte-blob that contains the elements of the given byte-blob in reverse order.
[procedure] (byte-blob-intersperse BYTE-BLOB BYTE) => BYTE-BLOBReturns a byte-blob with the given byte placed between the elements of the given byte-blob.
[procedure] (byte-blob-map F BYTE-BLOB) => BYTE-BLOBReturns a byte-blob obtained by applying F to each element of the given byte-blob.
[procedure] (byte-blob->blob BYTE-BLOB) => BLOBReturns the underlying Scheme blob object.
[procedure] (byte-blob->list BYTE-BLOB [F]) => LISTReturns 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.
[procedure] (byte-blob->string BYTE-BLOB) => STRINGReturns a string containing the elements of the given byte-blob.
Subsequences
[procedure] (byte-blob-take BYTE-BLOB N) => BYTE-BLOBReturns the prefix of the given byte-blob of length N.
[procedure] (byte-blob-drop BYTE-BLOB N) => BYTE-BLOBReturns the suffix of the given byte-blob after the first N elements.
[procedure] (byte-blob-span BYTE-BLOB START END) => BYTE-BLOBReturns 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) => LISTFinds 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] (file->byte-blob FILENAME [MODE]) => BYTE-BLOBReturns 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.
[procedure] (byte-blob-read PORT N) => BYTE-BLOBReads 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.
[procedure] (byte-blob-write PORT BYTE-BLOB) => UNDEFINEDWrites 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
[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
- 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/>.