[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some I/O Questions

From: Ian Price
Subject: Re: Some I/O Questions
Date: Fri, 10 Feb 2012 20:05:09 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Luiji Maryo <address@hidden> writes:

> Hello,
> I have some questions regarding Guile I/O and byte order.
If you are dealing with binary data, you should be using bytevectors and
binary ports, rather than strings.

> 1. Is there an I/O function for reading a fixed set of bytes into a
> buffer, i.e. if I wanted to read a 56-byte string from a binary
> archive?

For this, In (ice-9 binary-ports) or (rnrs io ports), there is 

> 2. Is there a way to specifically read a 8/16/32/64-bit string from a 
> file/port?
For reading bytes you can use 'get-u8', and for reading multiple bytes
as a bytevector 'get-bytevector-n'. (rnrs bytevectors) contains
procedures for setting/getting 8/16/32/64 bit quantities.

> 3. Is there a built-in function for converting between byte orders
> (i.e. BSD-style htobe32 and such) or must I implement them myself?
(rnrs bytevectors) has procedures for dealing with endianness, at the
bytevector level. So I can, for instance, use
(bytevector-u16-ref bv index (native-endianness)) to extract a 16 bit
integer from a given index in a bytevector. If you wanted to specify a
particular endianness, I could use (endianness big) or (endianness

For integers you could use ntohs, ntohl, htons, htonl, but that is
native endianness <-> network order only.

> 4. Is writing an archive manager using Guile for implementing archive
> formats a bad idea to start with?
Writing in Scheme is never a bad idea. ;-)

Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]