From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Price Newsgroups: gmane.lisp.guile.user Subject: Re: Some I/O Questions Date: Fri, 10 Feb 2012 20:05:09 +0000 Message-ID: <874nuyzc7e.fsf@Kagami.home> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1328904805 4857 80.91.229.3 (10 Feb 2012 20:13:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Feb 2012 20:13:25 +0000 (UTC) Cc: Guile Mailing List To: Luiji Maryo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Feb 10 21:13:25 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RvwqQ-0002gO-Sc for guile-user@m.gmane.org; Fri, 10 Feb 2012 21:13:23 +0100 Original-Received: from localhost ([::1]:47402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvwqQ-00029r-5F for guile-user@m.gmane.org; Fri, 10 Feb 2012 15:13:22 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:55593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvwqG-00028t-CI for guile-user@gnu.org; Fri, 10 Feb 2012 15:13:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvwqC-0005XS-Ae for guile-user@gnu.org; Fri, 10 Feb 2012 15:13:12 -0500 Original-Received: from mail-wi0-f169.google.com ([209.85.212.169]:40408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvwqB-0005XL-T1 for guile-user@gnu.org; Fri, 10 Feb 2012 15:13:08 -0500 Original-Received: by wibhj13 with SMTP id hj13so2902002wib.0 for ; Fri, 10 Feb 2012 12:13:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=TIh7Hz8MN5zvT5Ll9lB7Tlzv84E0waD30GQcaODiiJU=; b=ind0k43llSMUXdgwN1tt4kNnNalAO+usxPvRT9Q8PuHBINw3H/dsul23sd6Pgqn77L lQk2ZB3jb/lXvKZ5xLF0n5GEeFVy2auh1RHY2SCoTNpqlFbFNCeWSWz/0yQ8ToEdEmc+ cZ6lgfsQ/zFoFxeLV73m3BewHi7Hg7TsRbuD8= Original-Received: by 10.180.104.4 with SMTP id ga4mr5319684wib.17.1328904786588; Fri, 10 Feb 2012 12:13:06 -0800 (PST) Original-Received: from Kagami.home (host86-179-78-109.range86-179.btcentralplus.com. [86.179.78.109]) by mx.google.com with ESMTPS id n5sm21042103wiw.7.2012.02.10.12.13.03 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 10 Feb 2012 12:13:04 -0800 (PST) In-Reply-To: (Luiji Maryo's message of "Thu, 9 Feb 2012 22:50:05 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.169 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9262 Archived-At: Luiji Maryo 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 'get-bytevector-n!' > 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 little). 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"