Next: , Previous: , Up: SRFI Support Modules   [Contents][Index]


7.5.49 SRFI-207 String-notated bytevectors

SRFI-207 provides a more human-friendly representation for binary-data via an ASCII text notation for see Bytevectors. It also provides bytestring-oriented procedures for constructing bytevectors from sequences of integers, characters, strings, and other bytevectors, and procedures for manipulating bytevectors as if they were strings.

Binary file formats are usually not self-describing, and if they are, the descriptive portion is itself binary, which makes it hard for human beings to interpret. To assist with this problem, it is common to have a human-readable section at the beginning of the file, or in some cases at the beginning of each distinct section of the file. For historical reasons and to avoid text encoding complications, it is usual for this human-readable section to be expressed as ASCII text.

For example, ZIP files begin with the hex bytes 50 4B which are the ASCII encoding for the characters "PK", the initials of Phil Katz, the inventor of ZIP format. As another example, the GIF image format begins with 47 49 46 38 39 61, the ASCII encoding for "GIF89a", where "89a" is the format version. A third example is the PNG image format, where the file header begins 89 50 4E 47. The first byte is intentionally non-ASCII, but the next three are "PNG". Furthermore, a PNG file is divided into chunks, each of which contains a 4-byte "chunk type" code. The letters in the chunk type are mnemonics for its purpose, such as "PLTE" for a palette, "bKGD" for a default background color, and "iTXt" for descriptive text in UTF-8.

When bytevectors contain string data of this kind, it is much more tractable for human programmers to deal with #u8"\x89;PNG\r\n\x1A;\n" rather than #u8(0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A).

In addition, this SRFI provides bytevectors with additional procedures that closely resemble those provided for strings. For example, bytevectors can be padded or trimmed, compared case-sensitively or case-insensitively, searched, joined, and split.

Most of the procedures of this SRFI begin with bytestring- in order to distinguish them from other bytevector procedures. This does not mean that they accept or return a separate bytestring type: bytestrings and bytevectors are exactly the same type.


Next: SRFI-244 - Multiple-value Definitions, Previous: SRFI-197: Pipeline Operators, Up: SRFI Support Modules   [Contents][Index]