From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: maillaxa@gmail.com Newsgroups: gmane.emacs.help Subject: Re: Read binary and pack/unpack functions ? Date: 21 Nov 2006 21:33:14 -0800 Organization: http://groups.google.com Message-ID: <1164173594.063442.170800@e3g2000cwe.googlegroups.com> References: <87u00sh0yz.fsf@zogzog.gnu-rox.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1164174038 10591 80.91.229.2 (22 Nov 2006 05:40:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2006 05:40:38 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 22 06:40:37 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GmkqZ-0006nF-20 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2006 06:40:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GmkqY-0004e2-CW for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2006 00:40:34 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!e3g2000cwe.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 41 Original-NNTP-Posting-Host: 213.41.184.169 Original-X-Trace: posting.google.com 1164173599 1317 127.0.0.1 (22 Nov 2006 05:33:19 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 22 Nov 2006 05:33:19 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.1) Gecko/20061111 BonEcho/2.0,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: e3g2000cwe.googlegroups.com; posting-host=213.41.184.169; posting-account=hqvwhA0AAAB_-XKLLeOWo9CNFx1vzERa Original-Xref: shelby.stanford.edu gnu.emacs.help:143257 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:38874 Archived-At: Kevin Rodgers a =E9crit : > Xavier Maillard wrote: > > Where iactually fail is at reading binary data from the file and > > packing binary data into a more "neutral" format based on sexp. > > > > Do you know any pack/unpack-like functions for GNU Emacs ? > > Are you familiar with Emacs coding systems? Yes I do and the problem is not with reading binary data but with "mapping" bytes into something that reflect the binary file format (header, data, ...). In perl you have two valuable functions called pack and unpack that takes a string and expands it out into a list of values. This is what I am looking for in emacs lisp. So is there anything similar ? Regards, Xavier P=2ES: here is what I am ending up for reading (temporary and subject to change. It basically load a file and try to read the first 72 bytes from there (corresponding to the file header) (defun load-memodb (file-name) (save-excursion (set-buffer (create-file-buffer file-name)) (erase-buffer) (if (fboundp 'set-buffer-multibyte) (set-buffer-multibyte t)) (let ((coding-system-for-read 'binary)) (insert-file-contents file-name)) (goto-char (point-min)) (setq header (memo-read-bytes 72))))